/// <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 static void reflectEnum(EnumRepresentation rep, Type type) { string[] names = type.GetEnumNames(); Array values = type.GetEnumValues(); for (int i = 0; i < names.Length; i++) { object o = Convert.ChangeType(values.GetValue(i), type.GetEnumUnderlyingType()); string value = o.ToString(); EnumRepresentation.EnumConstant ec = new EnumRepresentation.EnumConstant(names[i], value); rep.enumValues.Add(ec); } }