private void buildDelegate(DelegateRepTemplate d, Type t) { if (t.IsGenericType) { d.TypeName = t.GetGenericTypeDefinition().FullName; string[] tParams = new string[t.GetGenericArguments().Length]; for (int i = 0; i < t.GetGenericArguments().Length; i++) { tParams[i] = t.GetGenericArguments()[i].Name; } d.TypeParams = tParams; } else { d.TypeName = t.FullName; } MethodInfo invoker = t.GetMethod("Invoke"); if (invoker == null) { throw new Exception("Unexpected: class " + t.FullName + " inherits from System.Delegate but doesn't have an Invoke method"); } List <ParamRepTemplate> pars = new List <ParamRepTemplate>(); buildParameters(pars, invoker); d.Invoke = new InvokeRepTemplate(TypeHelper.buildTypeName(invoker.ReturnType), "Invoke", null, pars); }
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; }
private void buildDelegate(DelegateRepTemplate d, Type t) { if (t.IsGenericType) { d.TypeName = t.GetGenericTypeDefinition().FullName; string[] tParams = new string[t.GetGenericArguments().Length]; for (int i = 0; i < t.GetGenericArguments().Length; i++) { tParams[i] = t.GetGenericArguments()[i].Name; } d.TypeParams = tParams; } else { d.TypeName = t.FullName; } MethodInfo invoker = t.GetMethod("Invoke"); if (invoker == null) throw new Exception("Unexpected: class " + t.FullName + " inherits from System.Delegate but doesn't have an Invoke method"); List<ParamRepTemplate> pars = new List<ParamRepTemplate>(); buildParameters(pars, invoker); d.Invoke = new InvokeRepTemplate(TypeHelper.buildTypeName(invoker.ReturnType), "Invoke", null, pars); }