Beispiel #1
0
    public static int AddTypeInfo(Type type, out ATypeInfo tiOut)
    {
        ATypeInfo ti = new ATypeInfo();

        ti.fields       = type.GetFields(JSMgr.BindingFlagsField);
        ti.properties   = type.GetProperties(JSMgr.BindingFlagsProperty);
        ti.methods      = type.GetMethods(JSMgr.BindingFlagsMethod);
        ti.constructors = type.GetConstructors();
        if (JSBindingSettings.NeedGenDefaultConstructor(type))
        {
            // null means it's default constructor
            var l = new List <ConstructorInfo>();
            l.Add(null);
            l.AddRange(ti.constructors);
            ti.constructors = l.ToArray();
        }
        ti.howmanyConstructors = ti.constructors.Length;

        FilterTypeInfo(type, ti);

        int slot = allTypeInfo.Count;

        allTypeInfo.Add(ti);
        tiOut = ti;
        return(slot);
    }
Beispiel #2
0
        public static int AddTypeInfo(Type type, out ATypeInfo tiOut)
        {
            ATypeInfo ti = CreateTypeInfo(type);

            int slot = allTypeInfo.Count;

            allTypeInfo.Add(ti);
            tiOut = ti;
            return(slot);
        }
Beispiel #3
0
    public static int AddTypeInfo(Type type, out ATypeInfo tiOut)
    {
        ATypeInfo ti = new ATypeInfo();

        ti.fields       = type.GetFields(BindingFlags.Public | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance | BindingFlags.Static);
        ti.properties   = type.GetProperties(BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Static);
        ti.methods      = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
        ti.constructors = type.GetConstructors();

        FilterTypeInfo(type, ti);

        int slot = allTypeInfo.Count;

        allTypeInfo.Add(ti);
        tiOut = ti;
        return(slot);
    }
    public static int AddTypeInfo(Type type, out ATypeInfo tiOut)
    {
        ATypeInfo ti = new ATypeInfo();
        ti.fields = type.GetFields(JSMgr.BindingFlagsField);
        ti.properties = type.GetProperties(JSMgr.BindingFlagsProperty);
        ti.methods = type.GetMethods(JSMgr.BindingFlagsMethod);
        ti.constructors = type.GetConstructors();
        if (JSBindingSettings.NeedGenDefaultConstructor(type))
        {
            // null means it's default constructor
            var l = new List<ConstructorInfo>();
            l.Add(null);
            l.AddRange(ti.constructors);
            ti.constructors = l.ToArray();
        }
        ti.howmanyConstructors = ti.constructors.Length;

        FilterTypeInfo(type, ti);

        int slot = allTypeInfo.Count;
        allTypeInfo.Add(ti);
        tiOut = ti;
        return slot;
    }
Beispiel #5
0
        public static int AddTypeInfo(Type type)
        {
            ATypeInfo tiOut = new ATypeInfo();

            return(AddTypeInfo(type, out tiOut));
        }
Beispiel #6
0
        public static ATypeInfo CreateTypeInfo(Type type)
        {
            ATypeInfo ti = new ATypeInfo();
            {
                var fields = type.GetFields(JSMgr.BindingFlagsField);
                for (int i = 0; i < fields.Length; i++)
                {
                    ti.Fields.Add(new MemberInfoEx(ti.Fields, fields[i], fields[i].IsStatic));
                }

                var pros = type.GetProperties(JSMgr.BindingFlagsProperty);
                for (int i = 0; i < pros.Length; i++)
                {
                    ti.Pros.Add(new MemberInfoEx(ti.Pros, pros[i], pros[i].GetAccessors()[0].IsStatic));
                }

                ti.Pros.Sort(PropertyInfoComparison);

                var methods = type.GetMethods(JSMgr.BindingFlagsMethod);
                for (int i = 0; i < methods.Length; i++)
                {
                    ti.Methods.Add(new MemberInfoEx(ti.Methods, methods[i], methods[i].IsStatic));
                }

                // 函数排序
                ti.Methods.Sort(MethodBaseComparison);

                var cons = type.GetConstructors();
                if (JSBindingSettings.NeedGenDefaultConstructor(type))
                {
                    // null 表示默认构造函数
                    var l = new List <ConstructorInfo>();
                    l.Add(null);
                    l.AddRange(cons);
                    cons = l.ToArray();
                }
                for (int i = 0; i < cons.Length; i++)
                {
                    ti.Cons.Add(new MemberInfoEx(ti.Cons, cons[i], false));
                }

                ti.Cons.Sort(MethodBaseComparison);
            }

            bool isStaticClass   = (type.IsClass && type.IsAbstract && type.IsSealed);
            bool isAbstractClass = (type.IsClass && type.IsAbstract);

            Dictionary <string, int> proAccessors = new Dictionary <string, int>();

            for (int i = 0; i < ti.Cons.Count; i++)
            {
                MemberInfoEx    infoEx = ti.Cons[i];
                ConstructorInfo con    = infoEx.member as ConstructorInfo;
                if (con == null)
                {
                    continue;
                }

                if (isAbstractClass ||
                    //type == typeof(UnityEngine.MonoBehaviour) ||
                    IsMemberObsolete(con) ||
                    JSBindingSettings.IsDiscard(type, con)
                    )
                {
                    infoEx.Ignored = true;
                    continue;
                }

                ParameterInfo[] ps = con.GetParameters();
                for (var k = 0; k < ps.Length; k++)
                {
                    Type pt = ps[k].ParameterType;
                    if (TypeIsPtr(pt))
                    {
                        infoEx.Ignored = true;
                        continue;
                    }
                }
            }

            for (int i = 0; i < ti.Fields.Count; i++)
            {
                MemberInfoEx infoEx = ti.Fields[i];
                FieldInfo    field  = infoEx.member as FieldInfo;

                if (typeof(System.Delegate).IsAssignableFrom(field.FieldType.BaseType))
                {
                    //Debug.Log("[field]" + type.ToString() + "." + ti.fields[i].Name + "is delegate!");
                }

                if (field.FieldType.ContainsGenericParameters ||
                    IsMemberObsolete(field) ||
                    JSBindingSettings.IsDiscard(type, field)
                    )
                {
                    infoEx.Ignored = true;
                }
            }

            for (int i = 0; i < ti.Pros.Count; i++)
            {
                MemberInfoEx infoEx = ti.Pros[i];
                PropertyInfo pro    = infoEx.member as PropertyInfo;

                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);
                    }
                }

                // Skip Obsolete
                if (IsMemberObsolete(pro) ||
                    TypeIsPtr(pro.PropertyType) ||
                    JSBindingSettings.IsDiscard(type, pro)
                    )
                {
                    infoEx.Ignored = true;
                }
            }

            for (int i = 0; i < ti.Methods.Count; i++)
            {
                MemberInfoEx infoEx = ti.Methods[i];
                MethodInfo   method = infoEx.member as MethodInfo;

                // skip non-static method in static class
                if ((isStaticClass && !method.IsStatic) ||
                    (method.IsSpecialName && proAccessors.ContainsKey(method.Name))
                    )
                {
                    infoEx.Ignored = true;
                    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("忽略非静态特殊名字函数 " + type.Name + "." + method.Name);
                            infoEx.Ignored = true;
                            continue;
                        }
                    }
                    else
                    {
                        Debug.Log("忽略特殊名字函数 " + type.Name + "." + method.Name);
                        infoEx.Ignored = true;
                        continue;
                    }
                }

                // Skip Obsolete
                if (IsMemberObsolete(method))
                {
                    infoEx.Ignored = true;
                    continue;
                }

                ParameterInfo[] ps;
                bool            bDiscard = false;

                // 忽略掉类型带 T 的静态方法
                // 因为 SharpKit 调用时没有提供 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("忽略静态函数 " + type.Name + "." + method.Name);
                        infoEx.Ignored = true;
                        continue;
                    }
                }

                if (ShouldIgnoreTypeInM(type, method, method.ReturnType))
                {
                    Debug.Log(type.Name + "." + method.Name + " 忽略,因为返回值类型是逻辑类型");
                    infoEx.Ignored = true;
                    continue;
                }

                if (TypeIsPtr(method.ReturnType))
                {
                    Debug.Log(type.Name + "." + method.Name + " 忽略,因为返回值类型是 IntPtr");
                    infoEx.Ignored = true;
                    continue;
                }

                // 是否有 unsafe 的参数?
                bDiscard = false;
                ps       = method.GetParameters();
                for (var k = 0; k < ps.Length; k++)
                {
                    Type pt = ps[k].ParameterType;
                    if (TypeIsPtr(pt))
                    {
                        bDiscard = true;
                        break;
                    }
                }
                if (bDiscard)
                {
                    Debug.Log(type.Name + "." + method.Name + " 忽略,因为他有 IsPointer = true 的参数");
                    infoEx.Ignored = true;
                    continue;
                }

                bDiscard = false;
                for (var k = 0; k < ps.Length; k++)
                {
                    Type pt = ps[k].ParameterType;
                    if (ShouldIgnoreTypeInM(type, method, pt))
                    {
                        bDiscard = true;
                        break;
                    }
                }
                if (bDiscard)
                {
                    Debug.Log(type.Name + "." + method.Name + " 忽略,因为他的参数有逻辑类型");
                    infoEx.Ignored = true;
                    continue;
                }

                if (JSBindingSettings.IsDiscard(type, method))
                {
                    infoEx.Ignored = true;
                    continue;
                }
            }

            // 移除 Ignored 的项
            foreach (List <MemberInfoEx> lst in
                     new List <MemberInfoEx>[] { ti.Cons, ti.Fields, ti.Pros, ti.Methods })
            {
                for (int i = lst.Count - 1; i >= 0; i--)
                {
                    if (lst[i].Ignored)
                    {
                        lst.RemoveAt(i);
                    }
                }
            }
            return(ti);
        }
Beispiel #7
0
    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();
    }
Beispiel #8
0
    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;
        }
    }
    public static void FilterTypeInfo(Type type, ATypeInfo ti)
    {
        bool bIsStaticClass = (type.IsClass && type.IsAbstract && type.IsSealed);

        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 (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.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;

            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;
        }
    }
 public static int AddTypeInfo(Type type)
 {
     ATypeInfo tiOut = new ATypeInfo();
     return AddTypeInfo(type, out tiOut);
 }