public static void FilterTypeInfo(Type type, ATypeInfo ti) { List <ConstructorInfo> lstCons = new List <ConstructorInfo>(); List <FieldInfo> lstField = new List <FieldInfo>(); List <PropertyInfo> lstPro = new List <PropertyInfo>(); Dictionary <string, int> proAccessors = new Dictionary <string, int>(); List <MethodInfo> lstMethod = new List <MethodInfo>(); for (int i = 0; i < ti.constructors.Length; i++) { if (!IsMemberObsolete(ti.constructors[i])) { lstCons.Add(ti.constructors[i]); } } for (int i = 0; i < ti.fields.Length; i++) { if (typeof(System.Delegate).IsAssignableFrom(ti.fields[i].FieldType.BaseType)) { //Debug.Log("[field]" + type.ToString() + "." + ti.fields[i].Name + "is delegate!"); } if (!IsMemberObsolete(ti.fields[i]) && !JSBindingSettings.IsDiscard(type, ti.fields[i])) { lstField.Add(ti.fields[i]); } } for (int i = 0; i < ti.properties.Length; i++) { PropertyInfo pro = ti.properties[i]; if (typeof(System.Delegate).IsAssignableFrom(pro.PropertyType.BaseType)) { // Debug.Log("[property]" + type.ToString() + "." + pro.Name + "is delegate!"); } MethodInfo[] accessors = pro.GetAccessors(); foreach (var v in accessors) { if (!proAccessors.ContainsKey(v.Name)) { proAccessors.Add(v.Name, 0); } } if (pro.Name == "Item") //[] not support { continue; } // Skip Obsolete if (IsMemberObsolete(pro)) { continue; } if (JSBindingSettings.IsDiscard(type, pro)) { continue; } lstPro.Add(pro); } for (int i = 0; i < ti.methods.Length; i++) { MethodInfo method = ti.methods[i]; // skip property accessor if (method.IsSpecialName && proAccessors.ContainsKey(method.Name)) { continue; } if (method.IsSpecialName) { if (method.Name == "op_Addition" || method.Name == "op_Subtraction" || method.Name == "op_UnaryNegation" || method.Name == "op_Multiply" || method.Name == "op_Division" || method.Name == "op_Equality" || method.Name == "op_Inequality") { if (!method.IsStatic) { // Debug.LogWarning("IGNORE not-static special-name function: " + type.Name + "." + method.Name); continue; } } else { // Debug.LogWarning("IGNORE special-name function:" + type.Name + "." + method.Name); continue; } } // Skip Obsolete if (IsMemberObsolete(method)) { continue; } if (method.IsGenericMethod || method.IsGenericMethodDefinition) { //Debug.Log(type.Name + "." + method.Name); continue; } if (JSBindingSettings.IsDiscard(type, method)) { continue; } lstMethod.Add(method); } if (lstMethod.Count == 0) { ti.methodsOLInfo = null; } else { // sort methods lstMethod.Sort(MethodInfoComparison); ti.methodsOLInfo = new int[lstMethod.Count]; } int overloadedIndex = 1; bool bOL = false; for (int i = 0; i < lstMethod.Count; i++) { ti.methodsOLInfo[i] = 0; if (bOL) { ti.methodsOLInfo[i] = overloadedIndex; } if (i < lstMethod.Count - 1 && lstMethod[i].Name == lstMethod[i + 1].Name && ((lstMethod[i].IsStatic && lstMethod[i + 1].IsStatic) || (!lstMethod[i].IsStatic && !lstMethod[i + 1].IsStatic))) { if (!bOL) { overloadedIndex = 1; bOL = true; ti.methodsOLInfo[i] = overloadedIndex; } overloadedIndex++; } else { bOL = false; overloadedIndex = 1; } } ti.constructors = lstCons.ToArray(); ti.fields = lstField.ToArray(); ti.properties = lstPro.ToArray(); ti.methods = lstMethod.ToArray(); }
public static void FilterTypeInfo(Type type, ATypeInfo ti) { bool bIsStaticClass = (type.IsClass && type.IsAbstract && type.IsSealed); bool bIsAbstractClass = (type.IsClass && type.IsAbstract); List <ConstructorInfoAndIndex> lstCons = new List <ConstructorInfoAndIndex>(); List <FieldInfoAndIndex> lstField = new List <FieldInfoAndIndex>(); List <PropertyInfoAndIndex> lstPro = new List <PropertyInfoAndIndex>(); Dictionary <string, int> proAccessors = new Dictionary <string, int>(); List <MethodInfoAndIndex> lstMethod = new List <MethodInfoAndIndex>(); for (int i = 0; i < ti.constructors.Length; i++) { if (bIsAbstractClass) { continue; } if (ti.constructors[i] == null) { lstCons.Add(new ConstructorInfoAndIndex(null, i)); continue; } // don't generate MonoBehaviour constructor if (type == typeof(UnityEngine.MonoBehaviour)) { continue; } if (!IsMemberObsolete(ti.constructors[i]) && !JSBindingSettings.IsDiscard(type, ti.constructors[i])) { lstCons.Add(new ConstructorInfoAndIndex(ti.constructors[i], i)); } } for (int i = 0; i < ti.fields.Length; i++) { if (typeof(System.Delegate).IsAssignableFrom(ti.fields[i].FieldType.BaseType)) { //Debug.Log("[field]" + type.ToString() + "." + ti.fields[i].Name + "is delegate!"); } if (ti.fields[i].FieldType.ContainsGenericParameters) { continue; } if (!IsMemberObsolete(ti.fields[i]) && !JSBindingSettings.IsDiscard(type, ti.fields[i])) { lstField.Add(new FieldInfoAndIndex(ti.fields[i], i)); } } for (int i = 0; i < ti.properties.Length; i++) { PropertyInfo pro = ti.properties[i]; if (typeof(System.Delegate).IsAssignableFrom(pro.PropertyType.BaseType)) { // Debug.Log("[property]" + type.ToString() + "." + pro.Name + "is delegate!"); } MethodInfo[] accessors = pro.GetAccessors(); foreach (var v in accessors) { if (!proAccessors.ContainsKey(v.Name)) { proAccessors.Add(v.Name, 0); } } // if (pro.GetIndexParameters().Length > 0) // continue; // if (pro.Name == "Item") //[] not support // continue; // Skip Obsolete if (IsMemberObsolete(pro)) { continue; } if (JSBindingSettings.IsDiscard(type, pro)) { continue; } lstPro.Add(new PropertyInfoAndIndex(pro, i)); } for (int i = 0; i < ti.methods.Length; i++) { MethodInfo method = ti.methods[i]; // skip non-static method in static class if (bIsStaticClass && !method.IsStatic) { // NGUITools //Debug.Log("........."+type.Name+"."+method.Name); continue; } // skip property accessor if (method.IsSpecialName && proAccessors.ContainsKey(method.Name)) { continue; } if (method.IsSpecialName) { if (method.Name == "op_Addition" || method.Name == "op_Subtraction" || method.Name == "op_UnaryNegation" || method.Name == "op_Multiply" || method.Name == "op_Division" || method.Name == "op_Equality" || method.Name == "op_Inequality" || method.Name == "op_LessThan" || method.Name == "op_LessThanOrEqual" || method.Name == "op_GreaterThan" || method.Name == "op_GreaterThanOrEqual" || method.Name == "op_Implicit") { if (!method.IsStatic) { Debug.Log("IGNORE not-static special-name function: " + type.Name + "." + method.Name); continue; } } else { Debug.Log("IGNORE special-name function:" + type.Name + "." + method.Name); continue; } } // Skip Obsolete if (IsMemberObsolete(method)) { continue; } ParameterInfo[] ps; bool bDiscard = false; // // ignore static method who contains T coming from class type // because there is no way to call it // SharpKit doesn't give c# the type of T // if (method.IsGenericMethodDefinition && /* || method.IsGenericMethod*/ method.IsStatic) { ps = method.GetParameters(); for (int k = 0; k < ps.Length; k++) { if (ps[k].ParameterType.ContainsGenericParameters) { var Ts = JSDataExchangeMgr.RecursivelyGetGenericParameters(ps[k].ParameterType); foreach (var t in Ts) { if (t.DeclaringMethod == null) { bDiscard = true; break; } } if (bDiscard) { break; } } } if (bDiscard) { Debug.LogWarning("Ignore static method " + type.Name + "." + method.Name); continue; } } // does it have unsafe parameter? bDiscard = false; ps = method.GetParameters(); for (var k = 0; k < ps.Length; k++) { Type pt = ps[k].ParameterType; while (true) { if (pt.IsPointer) { bDiscard = true; break; } else if (pt.HasElementType) { pt = pt.GetElementType(); } else { break; } } if (bDiscard) { break; } } if (bDiscard) { Debug.Log(type.Name + "." + method.Name + " was discard because it has unsafe parameter."); continue; } if (JSBindingSettings.IsDiscard(type, method)) { continue; } lstMethod.Add(new MethodInfoAndIndex(method, i)); } if (lstMethod.Count == 0) { ti.methodsOLInfo = null; } else { // sort methods lstMethod.Sort(MethodInfoComparison); ti.methodsOLInfo = new int[lstMethod.Count]; } int overloadedIndex = 1; bool bOL = false; for (int i = 0; i < lstMethod.Count; i++) { ti.methodsOLInfo[i] = 0; if (bOL) { ti.methodsOLInfo[i] = overloadedIndex; } if (i < lstMethod.Count - 1 && lstMethod[i].method.Name == lstMethod[i + 1].method.Name && ((lstMethod[i].method.IsStatic && lstMethod[i + 1].method.IsStatic) || (!lstMethod[i].method.IsStatic && !lstMethod[i + 1].method.IsStatic))) { if (!bOL) { overloadedIndex = 1; bOL = true; ti.methodsOLInfo[i] = overloadedIndex; } overloadedIndex++; } else { bOL = false; overloadedIndex = 1; } } ti.constructors = new ConstructorInfo[lstCons.Count]; ti.constructorsIndex = new int[lstCons.Count]; for (var k = 0; k < lstCons.Count; k++) { ti.constructors[k] = lstCons[k].method; ti.constructorsIndex[k] = lstCons[k].index; } // ti.fields = lstField.ToArray(); ti.fields = new FieldInfo[lstField.Count]; ti.fieldsIndex = new int[lstField.Count]; for (var k = 0; k < lstField.Count; k++) { ti.fields[k] = lstField[k].method; ti.fieldsIndex[k] = lstField[k].index; } // ti.properties = lstPro.ToArray(); ti.properties = new PropertyInfo[lstPro.Count]; ti.propertiesIndex = new int[lstPro.Count]; for (var k = 0; k < lstPro.Count; k++) { ti.properties[k] = lstPro[k].method; ti.propertiesIndex[k] = lstPro[k].index; } ti.methods = new MethodInfo[lstMethod.Count]; ti.methodsIndex = new int[lstMethod.Count]; for (var k = 0; k < lstMethod.Count; k++) { ti.methods[k] = lstMethod[k].method; ti.methodsIndex[k] = lstMethod[k].index; } }