Пример #1
0
        public IEnumerable <CodeConstructor> RenderTemplateConstructor(object instance, KeyValuePair <MethodInfo, GenerateConstructor> templateConstructor)
        {
            CurrentAttribute = templateConstructor.Value;
            var attributes = templateConstructor.Key.GetCustomAttributes(typeof(TemplateAttribute), true).OfType <TemplateAttribute>().OrderBy(p => p.Priority).ToArray();

            bool success = true;

            foreach (var attribute in attributes)
            {
                if (!attribute.CanGenerate(instance, templateConstructor.Key, this))
                {
                    success = false;
                }
            }
            if (!success)
            {
                yield break;
            }


            // Default to designer file only
            if (!attributes.OfType <Inside>().Any())
            {
                if (!IsDesignerFile)
                {
                    yield break;
                }
            }

            if (Iterators.ContainsKey(templateConstructor.Key.Name))
            {
                var iterator = Iterators[templateConstructor.Key.Name];
                var items    = iterator(Data).OfType <IDiagramNodeItem>().ToArray();

                foreach (var item in items)
                {
                    if (ItemFilter != null && !ItemFilter(item))
                    {
                        continue;
                    }
                    Item = item;
                    yield return(RenderConstructor(instance, templateConstructor, item));
                }
            }
            else
            {
                Item = Data as IDiagramNodeItem;
                if (ItemFilter != null && !ItemFilter(Item))
                {
                    yield break;
                }
                yield return(RenderConstructor(instance, templateConstructor, Data as IDiagramNodeItem));
            }
        }
Пример #2
0
        public IEnumerable <CodeMemberMethod> RenderTemplateMethod(object instance, KeyValuePair <MethodInfo, GenerateMethod> templateMethod)
        {
            CurrentAttribute = templateMethod.Value;
            var attributes = templateMethod.Key.GetCustomAttributes(typeof(TemplateAttribute), true).OfType <TemplateAttribute>().OrderBy(p => p.Priority).ToArray();

            bool success = true;

            foreach (var attribute in attributes)
            {
                if (!attribute.CanGenerate(instance, templateMethod.Key, this))
                {
                    success = false;
                }
            }
            if (!success)
            {
                yield break;
            }

            // Default to designer file only
            if (!attributes.OfType <Inside>().Any())
            {
                if (!IsDesignerFile)
                {
                    yield break;
                }
            }
            // if (templateMethod.Value.Location == TemplateLocation.DesignerFile &&
            //     templateMethod.Value.Location != TemplateLocation.Both && !IsDesignerFile) yield break;
            // if (templateMethod.Value.Location == TemplateLocation.EditableFile &&
            //     templateMethod.Value.Location != TemplateLocation.Both && IsDesignerFile) yield break;

            // var forEachAttribute =
            //templateMethod.Key.GetCustomAttributes(typeof(TemplateForEach), true).FirstOrDefault() as
            //    TemplateForEach;

            // var iteratorName = templateMethod.Key.Name;
            // if (forEachAttribute != null)
            // {
            //     iteratorName = forEachAttribute.IteratorProperty;
            //     AddIterator(templateMethod.Key.Name,
            //         delegate(TData arg1)
            //         {
            //             return CreateIterator(instance, iteratorName, arg1);
            //         });
            // }

            if (Iterators.ContainsKey(templateMethod.Key.Name))
            {
                var iterator = Iterators[templateMethod.Key.Name];
                var items    = iterator(Data).OfType <IDiagramNodeItem>().ToArray();

                foreach (var item in items)
                {
                    Item = item;
                    if (ItemFilter != null && !ItemFilter(item))
                    {
                        continue;
                    }
                    var result = RenderMethod(instance, templateMethod, item);
                    foreach (var attribute in attributes)
                    {
                        attribute.Modify(instance, templateMethod.Key, this);
                    }
                    yield return(result);
                }
                Item = null;
            }
            else
            {
                Item = Data as IDiagramNodeItem;
                if (ItemFilter != null && !ItemFilter(Item))
                {
                    yield break;
                }
                var result = RenderMethod(instance, templateMethod, Data as IDiagramNodeItem);
                foreach (var attribute in attributes)
                {
                    attribute.Modify(instance, templateMethod.Key, this);
                }
                yield return(result);

                Item = null;
            }
        }
Пример #3
0
        public IEnumerable <CodeMemberProperty> RenderTemplateProperty(object instance, KeyValuePair <PropertyInfo, GenerateProperty> templateProperty)
        {
            CurrentAttribute = templateProperty.Value;
            var attributes = templateProperty.Key.GetCustomAttributes(typeof(TemplateAttribute), true).OfType <TemplateAttribute>().OrderBy(p => p.Priority).ToArray();

            bool success = true;

            foreach (var attribute in attributes)
            {
                if (!attribute.CanGenerate(instance, templateProperty.Key, this))
                {
                    success = false;
                }
            }
            if (!success)
            {
                yield break;
            }

            // Default to designer file only
            if (!attributes.OfType <Inside>().Any())
            {
                if (!IsDesignerFile)
                {
                    yield break;
                }
            }

            if (Iterators.ContainsKey(templateProperty.Key.Name))
            {
                var iterator = Iterators[templateProperty.Key.Name];
                var items    = iterator(Data).OfType <IDiagramNodeItem>().ToArray();

                foreach (var item in items)
                {
                    if (ItemFilter != null && !ItemFilter(item))
                    {
                        continue;
                    }
                    Item = item;

                    var domObject = RenderProperty(instance, templateProperty);
                    foreach (var attribute in attributes)
                    {
                        attribute.Modify(instance, templateProperty.Key, this);
                    }
                    CurrentDeclaration.Members.Add(domObject);
                    yield return(domObject);

                    InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.PropertyAdded(instance, this, domObject));
                }
                Item = null;
            }
            else
            {
                Item = Data as IDiagramNodeItem;
                if (ItemFilter != null && !ItemFilter(Item))
                {
                    yield break;
                }
                var domObject = RenderProperty(instance, templateProperty);
                foreach (var attribute in attributes)
                {
                    attribute.Modify(instance, templateProperty.Key, this);
                }
                CurrentDeclaration.Members.Add(domObject);
                yield return(domObject);

                InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.PropertyAdded(instance, this, domObject));
                Item = null;
            }
        }