private void BuildConstructor(ClassType classType, System.Reflection.ConstructorInfo constructorInfo) { var args = constructorInfo.GetParameters().Select( x => new { Type = storage.GetType(ConvertMSILNames(x.ParameterType)), Name = x.Name }); if (!args.Any(x => x.Type == null)) { var constructor = new ConstructorInfo(false, classType); foreach (var item in args) { constructor.AddArg(item.Name, item.Type); } classType.AddConstructor(constructor); } }
ClassType FillIn(ClassType t, System.Type type) { foreach (System.Type x in type.GetNestedTypes(flags)) { GetType(x); } foreach (FieldInfo x in type.GetFields(BindingFlags.Instance | BindingFlags.Static | flags)) { Field f = t.AddField(new InputElement(x.Name), msg); f.Modifiers = GetFieldModifiers(x); f.Type = GetType(x.FieldType); } foreach (ConstructorInfo x in type.GetConstructors(BindingFlags.Instance | BindingFlags.Static | flags)) { GetMethod(t.AddConstructor(new InputElement(t.Name), msg), x); } foreach (MethodInfo x in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | flags)) { if (x.Name == "get_Item" || x.Name == "set_Item" || type.FullName == "System.String" && x.Name == "get_Chars") { GetMethod(t, x.Name, x); // indexer } else if (x.Name.StartsWith("get_") || x.Name.StartsWith("set_")) { string name = x.Name.Substring(4); Property p = t.members[name] as Property; if (p == null) { p = t.AddProperty(new InputElement(name), msg); } p.Modifiers = GetMethodModifiers(x); Method m; if (x.Name.StartsWith("get_")) { m = p.AddGet(new InputElement(name)); p.Type = GetType(x.ReturnType); } else { m = p.AddSet(new InputElement(name)); m.Type = global.Types.Void; p.Type = GetType(x.GetParameters()[0].ParameterType); } } else { GetMethod(t, x.Name, x); } } t.Modifiers = GetTypeModifiers(type); IList baseinterfaces; if (type.BaseType != null) { t.baseClass = (ClassType)GetType(type.BaseType); baseinterfaces = type.BaseType.GetInterfaces(); } else { baseinterfaces = new System.Type[0]; } if (type.DeclaringType != null) { t.enclosingType = (ClassType)GetType(type.DeclaringType); } foreach (System.Type x in type.GetInterfaces()) { if (!baseinterfaces.Contains(x)) { t.interfaces.Add((InterfaceType)GetType(x)); } } return(t); }
ClassType FillIn(ClassType t, MetaDataTypeDefinition d, string path) { foreach (MetaDataTypeDefinition x in d.NestedClasses) { GetSymbol(x, path); } foreach (MetaDataField x in d.Fields) { Field f = t.AddField(new InputElement(x.Name), msg); f.Modifiers = GetFieldModifiers(x); f.Type = GetType(x.Signature.FieldType, path); } foreach (MetaDataMethod x in d.Methods) { if (x.Name == "get_Item" || x.Name == "set_Item" || d.FullName == "System.String" && x.Name == "get_Chars") { GetMethod(t, x.Name, x, path); // indexer } else if (x.Name.StartsWith("get_") || x.Name.StartsWith("set_")) { Property p; string name = x.Name.Substring(4); if (t.members.Contains(name)) { p = (Property)t.members[name]; } else { p = t.AddProperty(new InputElement(name), msg); } p.Modifiers = GetMethodModifiers(x); Method m; if (x.Name.StartsWith("get_")) { m = p.AddGet(new InputElement(name)); m.Type = GetType(x.Signature.ReturnType, path); } else { m = p.AddSet(new InputElement(name)); p.Type = GetType(x.Signature.Parameters[0].Type, path); m.Type = global.Types.Void; } m.Modifiers = p.Modifiers; } else if (x.Name == ".ctor") { GetMethod(t.AddConstructor(new InputElement(t.Name), msg), x, path); } else if (x.Name == ".cctor") { Constructor m = new Constructor(new InputElement(t.Name), t.members); GetMethod(m, x, path); } else { GetMethod(t, x.Name, x, path); } } t.Modifiers = GetTypeModifiers(d); t.baseClass = (ClassType)ResolveTypeRef(d.Extends, path); t.enclosingType = (ClassType)ResolveTypeRef(d.EnclosingClass, path); foreach (MetaDataObject x in d.Interfaces) { InterfaceType f = ResolveTypeRef(x, path) as InterfaceType; if (f != null) { t.interfaces.Add(f); } } return(t); }