public static List <string> Usings(this ClassGenerator generator)
        {
            var usings = new List <string>();

            for (int i = 0; i < generator.attributes.Count; i++)
            {
                usings.MergeUnique(generator.attributes[i].Usings());
            }

            for (int i = 0; i < generator.fields.Count; i++)
            {
                usings.MergeUnique(generator.fields[i].Usings());
            }

            for (int i = 0; i < generator.properties.Count; i++)
            {
                usings.MergeUnique(generator.properties[i].Usings());
            }

            for (int i = 0; i < generator.methods.Count; i++)
            {
                usings.MergeUnique(generator.methods[i].Usings());
            }

            return(usings);
        }
Beispiel #2
0
        /// <summary>
        /// Create a nested class generator based on required parameters.
        /// </summary>
        public static ClassGenerator Class(AccessModifier nestedScope, ClassModifier modifier, string name, Type inherits)
        {
            var @class = new ClassGenerator();

            @class.nestedScope = nestedScope;
            @class.modifier    = modifier;
            @class.name        = name;
            @class.inherits    = inherits == null ? typeof(object) : inherits;
            @class.isNested    = true;
            return(@class);
        }
Beispiel #3
0
        /// <summary>
        /// Create a root class generator based on required parameters.
        /// </summary>
        public static ClassGenerator Class(RootAccessModifier scope, ClassModifier modifier, string name, string inherits, string inheritsNamespace, List <string> usings = null)
        {
            var @class = new ClassGenerator();

            @class.scope    = scope;
            @class.modifier = modifier;
            @class.name     = name;
            @class.assemblyQualifiedInheritanceNamespace = inheritsNamespace;
            @class.assemblyQualifiedInheritanceType      = inherits;
            @class.isNested = false;
            @class.usings   = usings;
            @class.useAssemblyQualifiedNameForInheritance = true;
            return(@class);
        }
        public static string Using(this ClassGenerator generator)
        {
            var usings = new List <string>();

            for (int i = 0; i < generator.fields.Count; i++)
            {
                var @namespace = generator.fields[i].type.Namespace;
                if (!usings.Contains(@namespace))
                {
                    usings.Add(@namespace);
                }
            }

            for (int i = 0; i < generator.properties.Count; i++)
            {
                var @namespace = generator.properties[i].returnType.Namespace;
                if (!usings.Contains(@namespace))
                {
                    usings.Add(@namespace);
                }
            }

            for (int i = 0; i < generator.methods.Count; i++)
            {
                var @namespace = generator.methods[i].returnType.Namespace;
                if (!usings.Contains(@namespace))
                {
                    usings.Add(@namespace);
                }
            }

            var output = string.Empty;

            for (int i = 0; i < usings.Count; i++)
            {
                output += "using ".ConstructHighlight() + usings[i] + ";" + (i < usings.Count - 1 ? "\n" : string.Empty);
            }

            return(output);
        }
Beispiel #5
0
 public NamespaceGenerator AddClass(ClassGenerator @class)
 {
     classes.Add(@class);
     return(this);
 }
Beispiel #6
0
 /// <summary>
 /// Adds a nested class to this class.
 /// </summary>
 /// <param name="generator"></param>
 /// <returns></returns>
 public ClassGenerator AddClass(ClassGenerator generator)
 {
     classes.Add(generator);
     return(this);
 }