예제 #1
0
 public void AddType(Type newType)
 {
     if (!newType.IsNested)
     {
         if (newType.IsClass)
         {
             NodableClass newClass = new NodableClass(newType);
             this.classes.Add(newClass);
         }
         else if (newType.IsInterface)
         {
             NodableInterface newInterface = new NodableInterface(newType);
             this.interfaces.Add(newInterface);
         }
         else if (newType.IsEnum)
         {
         }
     }
 }
예제 #2
0
        public NodableClass(Type classType)
        {
            this._name = classType.Name;
            BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
                                        BindingFlags.Static | BindingFlags.DeclaredOnly;
            var constructors = classType.GetConstructors(bindingFlags);

            if (classType.IsPublic)
            {
                this.attributes.Add("public");
            }
            if (classType.IsSealed)
            {
                this.attributes.Add("sealed");
            }
            if (classType.IsAbstract)
            {
                this.attributes.Add("abstract");
            }
            var interfaces = classType.GetInterfaces();

            foreach (Type classInterface in interfaces)
            {
                this.interfaces.Add(classInterface.Name);
            }

            if (classType.BaseType != null && classType.BaseType.Name != "Object")
            {
                this.baseClass = classType.BaseType.Name;
            }
            for (int i = 0; i < constructors.Length; i++)
            {
                var constructor = new NodableMethod(constructors[i]);
                this.constructors.Add(constructor);
            }
            var nestedTypes = classType.GetNestedTypes(bindingFlags);

            foreach (Type newType in nestedTypes)
            {
                if (newType.IsClass)
                {
                    NodableClass newClass = new NodableClass(newType);
                    this.nestedTypes.Add(newClass);
                }
                else if (newType.IsInterface)
                {
                    NodableInterface newInterface = new NodableInterface(newType);
                    this.nestedTypes.Add(newInterface);
                }
            }
            var methods = classType.GetMethods(bindingFlags);

            foreach (MethodBase method in methods.Where(method => !method.IsDefined(typeof(ExtensionAttribute), false)))
            {
                this.methods.Add(new NodableMethod(method));
            }
            var properties = classType.GetProperties(bindingFlags);

            foreach (PropertyInfo property in properties.Where(property => !property.IsDefined(typeof(ExtensionAttribute), false)))
            {
                this.properties.Add(new NodableProperty(property));
            }
            var fields = classType.GetFields(bindingFlags);

            foreach (FieldInfo fieldInfo in fields)
            {
                this.fields.Add(new NodableField(fieldInfo));
            }
        }