Exemplo n.º 1
0
        private PropertyRepresentation parsePropRep(PropertyInfo property)
        {
            string                 name     = property.Name;
            ObjectType             propType = ObjectType.toObjectType(property.PropertyType);
            PropertyRepresentation propRep  = new PropertyRepresentation(propType, name);

            propRep.attributes = getAttributes(property);
            if (property.DeclaringType != property.ReflectedType)
            {
                propRep.inheritedFrom = property.DeclaringType.FullName;
            }
            propRep.modifiers.Add(convert(property.GetGetMethod(true)));
            if (propRep.modifiers.Contains(Member.Modifier.PRIVATE))
            {
                return(null);
            }
            if (convert(property.GetGetMethod(true)) >= Member.Modifier.PROTECTED)
            {
                propRep.getter = true;
            }
            if (convert(property.GetSetMethod(true)) >= Member.Modifier.PROTECTED)
            {
                propRep.setter = true;
            }
            return(propRep);
        }
Exemplo n.º 2
0
        private void reflectFields(ClassRepresentation rep, Type type)
        {
            foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                try {
                    if (field.IsPrivate || field.IsAssembly)
                    {
                        continue;
                    }
                    string              name      = field.Name;
                    ObjectType          fieldType = ObjectType.toObjectType(field.FieldType);
                    FieldRepresentation fieldRep  = new FieldRepresentation(fieldType, name);
                    fieldRep.attributes = getAttributes(field);
                    if (field.DeclaringType != field.ReflectedType)
                    {
                        fieldRep.inheritedFrom = field.DeclaringType.FullName;
                    }
                    convert(fieldRep.modifiers, field);
                    rep.instanceFields.Add(fieldRep);
                }
                catch (TypeLoadException ex) {
                    Console.WriteLine(ex);
                }
            }

            foreach (FieldInfo field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (field.IsPrivate || field.IsAssembly)
                {
                    continue;
                }
                if (field.Name == "OnFlyByWire")
                {
                    getAttributes(field);
                }
                string              name      = field.Name;
                ObjectType          fieldType = ObjectType.toObjectType(field.FieldType);
                FieldRepresentation fieldRep  = new FieldRepresentation(fieldType, name);
                fieldRep.attributes = getAttributes(field);
                if (field.DeclaringType != field.ReflectedType)
                {
                    fieldRep.inheritedFrom = field.DeclaringType.FullName;
                }

                convert(fieldRep.modifiers, field);
                if (field.IsLiteral)
                {
                    object val = field.GetRawConstantValue();
                    fieldRep.assignment = val.ToString();
                    fieldRep.modifiers.Add(Member.Modifier.CONSTANT);
                }
                else
                {
                    fieldRep.modifiers.Add(Member.Modifier.STATIC);
                }

                rep.staticFields.Add(fieldRep);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// reflects on a Type object (class, enum, struct or interface) (the ones that can be top level
        /// </summary>
        /// <param name="type"></param>
        /// <returns>A representation of that type</returns>
        public static TopLevelDocumentable reflectTopOrNested(Type type)
        {
            if (type.IsGenericType)
            {
                Debug.WriteLine("Generic type found");
                foreach (Type arg in type.GetGenericArguments())
                {
                    Debug.WriteLine(arg.ToString());
                }
            }
            TopLevelDocumentable rep = null;

            if (type.IsEnum)
            {
                rep = new EnumRepresentation(type.FullName);
                reflectEnum((EnumRepresentation)rep, type);
            }
            else if (type.IsClass)
            {
                ObjectType ot = ObjectType.toObjectType(type);
                rep = new ClassRepresentation(ot.typeName);
                ((ClassRepresentation)rep).varargs = ot.varargs;
                new ClassReflector().reflectClass((ClassRepresentation)rep, type);
            }
            else if (type.IsInterface)
            {
                ObjectType ot = ObjectType.toObjectType(type);
                rep = new ClassRepresentation(ot.typeName);
                rep.objectType.typeName            = "interface";
                ((ClassRepresentation)rep).varargs = ot.varargs;
                new ClassReflector().reflectClass((ClassRepresentation)rep, type);
            }
            else if (type.IsValueType)
            {
                ObjectType ot = ObjectType.toObjectType(type);
                rep = new ClassRepresentation(ot.typeName);
                rep.objectType.typeName            = "struct";
                ((ClassRepresentation)rep).varargs = ot.varargs;
                new ClassReflector().reflectClass((ClassRepresentation)rep, type);
            }

            else
            {
                return(null);
            }
            //TypeInfo ti = type..GetTypeInfo();

            rep.userGenerated = false;

            rep.namespaceName = type.Namespace;
            rep.assemblyName  = type.Assembly.GetName().Name;
            convert(rep.modifiers, type);
            return(rep);
        }
Exemplo n.º 4
0
        private MethodRepresentation mrep(MethodInfo method)
        {
            if (method.IsPrivate || method.IsAssembly || method.IsSpecialName)
            {
                return(null);
            }
            string               name       = method.Name;
            ObjectType           returnType = ObjectType.toObjectType(method.ReturnType);
            MethodRepresentation methodRep  = new MethodRepresentation(returnType, name);

            if (method.DeclaringType != method.ReflectedType)
            {
                methodRep.inheritedFrom = method.DeclaringType.FullName;
            }
            if (method.IsGenericMethod)
            {
                Type[]        gens    = method.GetGenericArguments();
                List <string> genArgs = new List <string>();
                foreach (Type genType in gens)
                {
                    object[] constraints = genType.GetGenericParameterConstraints();
                    string   argString   = genType.ToString();
                    if (constraints.Count() > 0)
                    {
                        argString += ":" + string.Join(",", constraints);
                    }
                    genArgs.Add(argString);
                }
                methodRep.genericArgs = genArgs;
            }
            methodRep.modifiers.Add(convert(method));
            methodRep.attributes = getAttributes(method);
            if (method.IsVirtual)
            {
                methodRep.modifiers.Add(Member.Modifier.VIRTUAL);
            }
            foreach (ParameterInfo param in method.GetParameters())
            {
                ObjectType paramType = ObjectType.toObjectType(param.ParameterType);
                string     paramName = param.Name;
                methodRep.parameters.Add(new Member(paramType, paramName));
            }
            return(methodRep);
        }
Exemplo n.º 5
0
 private void reflectConstructors(ClassRepresentation rep, Type type)
 {
     foreach (ConstructorInfo cons in type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
     {
         if (cons.IsPrivate || cons.IsAssembly)
         {
             continue;
         }
         string               name       = "*constructor*";
         ObjectType           returnType = ObjectType.toObjectType(type);
         MethodRepresentation methodRep  = new MethodRepresentation(returnType, name);
         methodRep.modifiers.Add(convert(cons));
         methodRep.attributes = getAttributes(cons);
         foreach (ParameterInfo param in cons.GetParameters())
         {
             ObjectType paramType = ObjectType.toObjectType(param.ParameterType);
             string     paramName = param.Name;
             methodRep.parameters.Add(new Member(paramType, paramName));
         }
         rep.constructors.Add(methodRep);
     }
 }