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); } }
/// <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); }
private void reflectSubtypes(ClassRepresentation rep, Type type) { foreach (Type t in type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { if (t.IsNestedPrivate) { continue; } TopLevelDocumentable td = APIReflector.reflectTopOrNested(t); rep.nested.Add(td); } }
private void reflectProperties(ClassRepresentation rep, Type type) { foreach (PropertyInfo property in type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { PropertyRepresentation proprep = parsePropRep(property); if (proprep != null) { proprep.modifiers.Add(Member.Modifier.STATIC); rep.staticProperties.Add(proprep); } } foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { PropertyRepresentation proprep = parsePropRep(property); if (proprep != null) { rep.instanceProperties.Add(proprep); } } }
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); } }
public void reflectClass(ClassRepresentation rep, Type type) { Type parent = type.BaseType; if (parent != null && parent != typeof(Object)) { rep.extensions.Add(parent.FullName); } foreach (Type t in type.GetInterfaces()) { rep.extensions.Add(t.FullName); } rep.attributes = getAttributes(type); reflectFields(rep, type); reflectProperties(rep, type); reflectMethods(rep, type); reflectConstructors(rep, type); reflectSubtypes(rep, type); }
private void reflectMethods(ClassRepresentation rep, Type type) { foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { MethodRepresentation methodRep = mrep(method); if (methodRep == null) { continue; } rep.instanceMethods.Add(methodRep); } foreach (MethodInfo method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { MethodRepresentation methodRep = mrep(method); if (methodRep == null) { continue; } methodRep.modifiers.Add(Member.Modifier.STATIC); rep.staticMethods.Add(methodRep); } }