private void buildClass(ClassRepTemplate klass, Type t) { // Grab common fields buildInterface(klass, t); // Grab Constructors foreach (ConstructorInfo c in t.GetConstructors()) { ConstructorRepTemplate consRep = new ConstructorRepTemplate(); buildParameters(consRep.Params, c); consRep.SurroundingType = klass; klass.Constructors.Add(consRep); } // Grab Fields foreach (FieldInfo f in t.GetFields()) { FieldRepTemplate fieldRep = new FieldRepTemplate(); fieldRep.Name = f.Name; fieldRep.Type = new TypeRepRef(TypeHelper.buildTypeName(f.FieldType)); klass.Fields.Add(fieldRep); } // Grab Casts foreach (MethodInfo m in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static)) { if (m.IsSpecialName && (m.Name == "op_Explicit" || m.Name == "op_Implicit")) { CastRepTemplate cast = new CastRepTemplate(); cast.To = new TypeRepRef(TypeHelper.buildTypeName(m.ReturnType)); cast.From = new TypeRepRef(TypeHelper.buildTypeName(m.GetParameters()[0].ParameterType)); klass.Casts.Add(cast); } } }
private IList <TypeRepTemplate> mkTemplates(string typeName) { List <TypeRepTemplate> rets = new List <TypeRepTemplate>(); Type t = assembly.GetType(typeName); if (t == null) { throw new Exception(String.Format("Type {0} not found", typeName)); } foreach (Type nestedTy in t.GetNestedTypes()) { foreach (TypeRepTemplate nestedRep in mkTemplates(nestedTy.FullName)) { rets.Add(nestedRep); } } TypeRepTemplate retRep = null; if (t.IsClass) { if (t.IsSubclassOf(typeof(System.Delegate))) { DelegateRepTemplate delRep = new DelegateRepTemplate(); buildDelegate(delRep, t); retRep = delRep; } else { ClassRepTemplate classRep = new ClassRepTemplate(); buildClass(classRep, t); retRep = classRep; } } else if (t.IsInterface) { InterfaceRepTemplate intRep = new InterfaceRepTemplate(); buildInterface(intRep, t); retRep = intRep; } else if (t.IsEnum) { EnumRepTemplate enumRep = new EnumRepTemplate(); enumRep.TypeName = TypeHelper.buildTypeName(t); foreach (FieldInfo f in t.GetFields(BindingFlags.Public | BindingFlags.Static)) { enumRep.Members.Add(new EnumMemberRepTemplate(f.Name, f.GetRawConstantValue().ToString())); } retRep = enumRep; } rets.Add(retRep); return(rets); }
private IList<TypeRepTemplate> mkTemplates(string typeName) { List<TypeRepTemplate> rets = new List<TypeRepTemplate>(); Type t = assembly.GetType(typeName); if (t == null) throw new Exception(String.Format("Type {0} not found", typeName)); foreach (Type nestedTy in t.GetNestedTypes()) { foreach (TypeRepTemplate nestedRep in mkTemplates(nestedTy.FullName)) { rets.Add(nestedRep); } } TypeRepTemplate retRep = null; if (t.IsClass) { if (t.IsSubclassOf(typeof(System.Delegate))) { DelegateRepTemplate delRep = new DelegateRepTemplate(); buildDelegate(delRep, t); retRep = delRep; } else { ClassRepTemplate classRep = new ClassRepTemplate(); buildClass(classRep, t); retRep = classRep; } } else if (t.IsInterface) { InterfaceRepTemplate intRep = new InterfaceRepTemplate(); buildInterface(intRep, t); retRep = intRep; } else if (t.IsEnum) { EnumRepTemplate enumRep = new EnumRepTemplate(); enumRep.TypeName = TypeHelper.buildTypeName(t); foreach (FieldInfo f in t.GetFields(BindingFlags.Public | BindingFlags.Static)) { enumRep.Members.Add(new EnumMemberRepTemplate(f.Name, f.GetRawConstantValue().ToString())); } retRep = enumRep; } rets.Add(retRep); return rets; }