Ejemplo n.º 1
0
 public Property(Type type, bool isStatic, bool canGet, bool canSet, string name, bool obsolete)
 {
     m_type     = WrapTextTools.Type2String(type);
     m_isStatic = isStatic;
     m_canGet   = canGet;
     m_canSet   = canSet;
     m_name     = name;
     m_obsolete = obsolete;
 }
Ejemplo n.º 2
0
    public Method(string methodType, Type returnType, string methodName, System.Reflection.ParameterInfo[] param, int paramLength, bool isGeneric, bool obsolete)
    {
        m_methodType = methodType;
        if (returnType != null)
        {
            m_returnType = WrapTextTools.Type2String(returnType);
        }
        ;
        m_methodName = methodName;
        m_inType     = new string[paramLength];

        for (int i = 0; i < paramLength; i++)
        {
            m_inType[i] = WrapTextTools.Type2String(param[i].ParameterType);
        }
        m_isGeneric = isGeneric;
        m_obsolete  = obsolete;
    }
Ejemplo n.º 3
0
    public static List <Method> GetInstanceMethods(Type type, ref string manifest, List <Property> ignoreProperty, List <string> filter)
    {
        List <Method> saveMethods = new List <Method> ();
        string        trueName    = GetTrueName(type);

        manifest += "\n成员方法\n";

        if (IsStaticClass(type))                //是否是静态类,静态类没有构造函数
        {
            manifest += "静态类没有成员方法";
            return(saveMethods);                                //静态类依然会反射出成员方法(比如ToString,GetType),但没法调用,我们不保存
        }

        System.Reflection.MethodInfo[] imis = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);         //这里没有获取私有方法,因为即使获取了西瓜也没有办法调用
        //基类的方法一起导出,这样可以自动调用基类

        PropertyInfo[] pis      = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
        bool           hasIndex = false;

        for (int i = 0; i < pis.Length; i++)
        {
            if (pis[i].Name == "Item")
            {
                hasIndex = true;
                break;
            }
        }
        for (int i = 0; i < imis.Length; i++)
        {
            if (filter.Contains(trueName + "." + imis[i].Name))           //成员黑名单
            {
                continue;
            }

            //属性上面已经获取过了 这里做个判断,是否包含这个属性,包含的话continue,否则表示有方法名是get_,set_开头
            if (ContainsProperty(ignoreProperty, imis[i].Name))
            {
                continue;
            }

            if (imis[i].Name == "get_Item" || imis[i].Name == "set_Item")
            {
                if (hasIndex)
                {
                    continue;
                }
            }

            string retType = WrapTextTools.Type2String(imis[i].ReturnType);

            bool   isObsolete = IsObsolete(imis[i]);
            string s          = "";
            if (isObsolete)
            {
                s += "[Obsolete]";
            }
            s += "public " + retType + " ";
            s += imis [i].Name;
            bool isGeneric = (imis[i].ContainsGenericParameters && imis[i].IsGenericMethod);
            if (isGeneric)
            {
                s += "<T>";
            }

            s += "(";
            System.Reflection.ParameterInfo[] param = imis [i].GetParameters();
            if (param.Length == 0)
            {
                saveMethods.Add(new Method("MCall", imis [i].ReturnType, imis [i].Name, param, 0, isGeneric, isObsolete));
            }
            else
            {
                if (param [0].IsOptional)
                {
                    saveMethods.Add(new Method("MCall", imis [i].ReturnType, imis [i].Name, param, 0, isGeneric, isObsolete));
                }
                for (int j = 0; j < param.Length; j++)
                {
                    string paramType = WrapTextTools.Type2String(param[j].ParameterType);
                    bool   finish    = true;
                    if (paramType.EndsWith("&"))                       //ref,out
                    {
                        s     += "ref " + paramType.Substring(0, paramType.Length - 1) + " " + param [j].Name;
                        finish = false;
                    }
                    else
                    {
                        s += paramType + " " + param [j].Name;
                        if (param [j].IsOptional)
                        {
                            s += " = " + param [j].DefaultValue;
                        }
                    }
                    if (j != param.Length - 1)
                    {
                        s += ", ";
                    }

                    if (finish)
                    {
                        if (j == param.Length - 1 || param [j + 1].IsOptional)
                        {
                            saveMethods.Add(new Method("MCall", imis [i].ReturnType, imis [i].Name, param, j + 1, isGeneric, isObsolete));
                        }
                    }
                }
            }
            s        += ")";
            manifest += s + "\n";
        }
        return(saveMethods);
    }
Ejemplo n.º 4
0
    public static List <Method> GetStaticMethods(Type type, ref string manifest, List <Property> ignoreProperty, List <string> filter)
    {
        List <Method> saveMethods = new List <Method> ();
        string        trueName    = GetTrueName(type);

        manifest += "\n静态方法\n";

        //TODO 不包含op,不包含index,暂时不包含ref,in, out, 不包含IEnumrator
        System.Reflection.MethodInfo[] smis = type.GetMethods(BindingFlags.Public | BindingFlags.Static);         //这里没有获取私有方法,因为即使获取了西瓜也没有办法调用
        //基类的方法一起导出,这样可以自动调用基类
        for (int i = 0; i < smis.Length; i++)
        {
            if (filter.Contains(trueName + "." + smis[i].Name))           //成员黑名单
            {
                continue;
            }

            //属性上面已经获取过了 这里做个判断,是否包含这个属性,包含的话continue,否则表示有方法名是get_,set_开头
            if (ContainsProperty(ignoreProperty, smis [i].Name))
            {
                continue;
            }

            if (IsOp(smis [i]))
            {
                continue;
            }

            string retType = WrapTextTools.Type2String(smis[i].ReturnType);

            bool   isObsolete = IsObsolete(smis[i]);
            string s          = "";
            if (isObsolete)
            {
                s += "[Obsolete]";
            }
            s += "public static " + retType + " ";
            s += smis [i].Name;
            bool isGeneric = (smis[i].ContainsGenericParameters && smis[i].IsGenericMethod);
            if (isGeneric)
            {
                s += "<T>";
            }
            s += "(";
            System.Reflection.ParameterInfo[] param = smis [i].GetParameters();
            if (param.Length == 0)
            {
                saveMethods.Add(new Method("SCall", smis [i].ReturnType, smis [i].Name, param, 0, isGeneric, isObsolete));
            }
            else
            {
                if (param [0].IsOptional)
                {
                    saveMethods.Add(new Method("SCall", smis [i].ReturnType, smis [i].Name, param, 0, isGeneric, isObsolete));
                }
                for (int j = 0; j < param.Length; j++)
                {
                    string paramType = WrapTextTools.Type2String(param[j].ParameterType);
                    bool   finish    = true;
                    if (paramType.EndsWith("&"))                       //ref,out
                    {
                        s     += "ref " + paramType.Substring(0, paramType.Length - 1) + " " + param [j].Name;
                        finish = false;
                    }
                    else
                    {
                        s += paramType + " " + param [j].Name;
                        if (param [j].IsOptional)
                        {
                            s += " = " + param [j].DefaultValue;
                        }
                    }
                    if (j != param.Length - 1)
                    {
                        s += ", ";
                    }

                    if (finish)
                    {
                        if (j == param.Length - 1 || param [j + 1].IsOptional)
                        {
                            saveMethods.Add(new Method("SCall", smis [i].ReturnType, smis [i].Name, param, j + 1, isGeneric, isObsolete));
                        }
                    }
                }
            }
            s        += ")";
            manifest += s + "\n";
        }
        return(saveMethods);
    }
Ejemplo n.º 5
0
    public static List <Property> GetPropertys(Type type, ref string manifest, List <string> filter)
    {
        List <Property> savePropertys = new List <Property>();
        string          trueName      = GetTrueName(type);

        manifest += "\n字段\n";
        FieldInfo[] fis = type.GetFields();
        for (int i = 0; i < fis.Length; i++)
        {
            if (filter.Contains(trueName + "." + fis[i].Name))           //成员黑名单
            {
                continue;
            }

            bool isObsolete = IsObsolete(fis[i]);
            if (isObsolete)
            {
                manifest += "[Obsolete]";
            }

            manifest += "public ";
            string attributes = fis[i].Attributes.ToString();
            bool   isStatic   = attributes.Contains("Static");
            if (isStatic)
            {
                manifest += "static ";
            }
            bool isReadonly = attributes.Contains("Literal") && attributes.Contains("HasDefault"); //const
            isReadonly |= attributes.Contains("InitOnly");                                         //readonly
            if (isReadonly)
            {
                manifest += "readonly ";
            }
            manifest += WrapTextTools.Type2String(fis[i].FieldType) + " " + fis[i].Name + ";\n";
            savePropertys.Add(new Property(fis[i].FieldType, isStatic, true, !isReadonly, fis[i].Name, isObsolete));
        }

        manifest += "\n静态属性\n";
        PropertyInfo[] spis = type.GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.SetProperty);
        for (int i = 0; i < spis.Length; i++)
        {
            if (filter.Contains(trueName + "." + spis[i].Name))           //成员黑名单
            {
                continue;
            }

            bool isObsolete = IsObsolete(spis[i]);
            if (isObsolete)
            {
                manifest += "[Obsolete]";
            }

            manifest += "public static ";
            manifest += WrapTextTools.Type2String(spis[i].PropertyType) + " " + spis[i].Name + "{";
            //这么判断的原因是可能是public Instance{get; private set;}
            if (spis[i].CanRead && spis[i].GetGetMethod(true).IsPublic)
            {
                manifest += "get;";
                savePropertys.Add(new Property(spis[i].PropertyType, true, true, false, spis[i].Name, isObsolete));
            }
            if (spis[i].CanWrite && spis[i].GetSetMethod(true).IsPublic)
            {
                manifest += "set;";
                savePropertys.Add(new Property(spis[i].PropertyType, true, false, true, spis[i].Name, isObsolete));
            }
            manifest += "}\n";
        }

        manifest += "\n实例属性\n";
        PropertyInfo[] pis = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
        //检查是否有Index
        MethodInfo[] mis      = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
        bool         hasIndex = false;

        for (int j = 0; j < mis.Length; j++)
        {
            if (mis[j].Name == "get_Item" || mis[j].Name == "set_Item")
            {
                hasIndex = true;
                break;
            }
        }

        for (int i = 0; i < pis.Length; i++)
        {
            bool isObsolete = IsObsolete(pis[i]);

            if (filter.Contains(trueName + "." + pis[i].Name))           //成员黑名单
            {
                continue;
            }

            if (pis[i].Name == "Item" && hasIndex)
            {
                continue;                //如果有get_Item或者set_Item,表示是[Index],否则表示一个属性
            }
            if (isObsolete)
            {
                manifest += "[Obsolete]";
            }
            manifest += "public ";
            manifest += WrapTextTools.Type2String(pis[i].PropertyType) + " " + pis[i].Name + "{";
            //这么判断的原因是可能是public Instance{get; private set;}
            if (pis[i].CanRead && pis[i].GetGetMethod(true).IsPublic)
            {
                manifest += "get;";
                savePropertys.Add(new Property(pis[i].PropertyType, false, true, false, pis[i].Name, isObsolete));
            }
            if (pis[i].CanWrite && pis[i].GetSetMethod(true).IsPublic)
            {
                manifest += "set;";
                savePropertys.Add(new Property(pis[i].PropertyType, false, false, true, pis[i].Name, isObsolete));
            }
            manifest += "}\n";
        }

        return(savePropertys);
    }