static void handleInterfaceProblems(TextFile tfClass, Type cType, Action <Type> OnNewType) { Type[] interfaces = cType.GetValidInterfaces(); Action <Type, MethodInfo> actionMethod = (iType, method) => { StringBuilder sbDef = new StringBuilder(); // sbDef.Append("extern "); if (!(method.IsSpecialName && method.Name == "op_Implicit")) { sbDef.Append(typefn(method.ReturnType, cType.Namespace, CsNameOption.CompilableWithT) + " "); } OnNewType(method.ReturnType); sbDef.Append(iType.CsFullName(CsNameOption.CompilableWithT) + "."); // 这句是重点 sbDef.Append(MethodNameString(cType, method)); if (method.IsGenericMethodDefinition) { Type[] argus = method.GetGenericArguments(); args t_args = new args(); foreach (var a in argus) { t_args.Add(a.Name); } sbDef.Append(t_args.Format(args.ArgsFormat.GenericT)); } sbDef.Append("("); ParameterInfo[] ps = method.GetParameters(); { sbDef.Append(Ps2String(cType, ps)); sbDef.Append(") { throw new Exception(\"Exception\"); }"); foreach (var p in ps) { OnNewType(p.ParameterType); } } tfClass.Add(sbDef.ToString()); }; Action <Type, PropertyInfo> actionPro = (iType, pro) => { OnNewType(pro.PropertyType); ParameterInfo[] ps = pro.GetIndexParameters(); args iargs = new args(); bool isIndexer = (ps.Length > 0); if (isIndexer) { for (int j = 0; j < ps.Length; j++) { iargs.AddFormat("{0} {1}", typefn(ps[j].ParameterType, cType.Namespace), ps[j].Name); OnNewType(ps[j].ParameterType); } } MethodInfo getm = pro.GetGetMethod(true); MethodInfo setm = pro.GetSetMethod(true); bool canGet = getm != null && getm.IsPublic; bool canSet = setm != null && setm.IsPublic; string getset = ""; { if (canGet) { getset += "get { throw new Exception(\"not impl\"); }"; } if (canSet) { getset += " set { throw new Exception(\"not impl\"); }"; } } string vo = string.Empty; if (isIndexer) { tfClass.Add("{4}{0} {1}{2} {{ {3} }}", typefn(pro.PropertyType, cType.Namespace), iType.CsFullName(CsNameOption.CompilableWithT) + ".this", // 这句是重点 iargs.Format(args.ArgsFormat.Indexer), getset, vo); } else { tfClass.Add("{3}{0} {1} {{ {2} }}", typefn(pro.PropertyType, cType.Namespace), iType.CsFullName(CsNameOption.CompilableWithT) + "." + // 这句是重点 pro.Name, getset, vo); } }; foreach (Type iType in interfaces) { GeneratorHelp.ATypeInfo ti = GeneratorHelp.CreateTypeInfo(iType); for (int i = 0; i < ti.Methods.Count; i++) { MemberInfoEx infoEx = ti.Methods[i]; MethodInfo method = infoEx.member as MethodInfo; actionMethod(iType, method); } for (int i = 0; i < ti.Pros.Count; i++) { MemberInfoEx infoEx = ti.Pros[i]; PropertyInfo pro = infoEx.member as PropertyInfo; actionPro(iType, pro); } // 特殊处理,BridgeProj工程 if (iType == typeof(ICollection)) { tfClass.Add("bool System.Collections.ICollection.IsReadOnly { get; }"); } } }
static void handlePros(TextFile tfClass, Type type, GeneratorHelp.ATypeInfo ti, Action <Type> OnNewType) { Action <PropertyInfo> action = (pro) => { // // ignore Experimental @eugenejiang // if (typefn(pro.PropertyType, type.Namespace).IndexOf("UnityEngine.Experimental.") >= 0) { // return; // } bool isI = type.IsInterface; OnNewType(pro.PropertyType); ParameterInfo[] ps = pro.GetIndexParameters(); args iargs = new args(); bool isIndexer = (ps.Length > 0); if (isIndexer) { for (int j = 0; j < ps.Length; j++) { iargs.AddFormat("{0} {1}", typefn(ps[j].ParameterType, type.Namespace), ps[j].Name); OnNewType(ps[j].ParameterType); } } MethodInfo getm = pro.GetGetMethod(true); MethodInfo setm = pro.GetSetMethod(true); bool canGet = getm != null && (getm.IsPublic || getm.IsFamily); bool canSet = setm != null && (setm.IsPublic || setm.IsFamily); string getset = ""; if (!isI) { if (canGet) { getset += string.Format("get {{ throw new Exception(\"not impl\"); }}", typefn(pro.PropertyType, type.Namespace)); } if (canSet) { getset += " set { throw new Exception(\"not impl\"); }"; } } else { if (canGet) { getset += "get;"; } if (canSet) { getset += " set;"; } } string vo = string.Empty; if (!isI) { vo = "public "; if ((getm != null && getm.IsStatic) || (setm != null && setm.IsStatic)) { vo += "static "; } if (!type.IsValueType) { if ((getm != null && getm.IsVirtual) || (setm != null && setm.IsVirtual)) { vo += ((getm != null && getm.GetBaseDefinition() != getm) || (setm != null && setm.GetBaseDefinition() != setm)) ? "override " : "virtual "; } } } if (isIndexer) { tfClass.Add("{3}{0} this{1} {{ {2} }}", typefn(pro.PropertyType, type.Namespace), iargs.Format(args.ArgsFormat.Indexer), getset, vo); } else { tfClass.Add("{3}{0} {1} {{ {2} }}", typefn(pro.PropertyType, type.Namespace), pro.Name, getset, vo); } }; bool hasNoneIndexer = false; for (int i = 0; i < ti.Pros.Count; i++) { MemberInfoEx infoEx = ti.Pros[i]; PropertyInfo pro = infoEx.member as PropertyInfo; if (pro.GetIndexParameters().Length == 0) { hasNoneIndexer = true; action(pro); } } if (hasNoneIndexer) { tfClass.AddLine(); } for (int i = 0; i < ti.Pros.Count; i++) { MemberInfoEx infoEx = ti.Pros[i]; PropertyInfo pro = infoEx.member as PropertyInfo; if (pro.GetIndexParameters().Length > 0) { action(pro); } } }