public static string GetMethodNativeFunctionName(System.Reflection.MethodInfo method, Type type, Dictionary <string, object> staticusenames, Dictionary <string, object> usenames)
        {
            string nativefunName;


            System.Reflection.PropertyInfo pinfo;
            if (MethodNativeCodeCreator.CheckIsIndexerGetter(method, type, out pinfo)

                && method.GetParameters().Length == 1
                )
            {
                string testname = GetMethodName(method.Name, false, method, type, staticusenames, usenames);
                if (testname == method.Name)
                {
                    testname = "getThisItem";
                }



                nativefunName = string.Format("{0}_{1}", GetNativeFunctionPart1(type), testname);                 // GetMethodName( "getThisItem" ,method,type,staticusenames,usenames ));
            }
            else if (MethodNativeCodeCreator.CheckIsGetter(method, type, out pinfo))
            {
                nativefunName = string.Format("{0}_{1}", GetNativeFunctionPart1(type), GetMethodName(method.Name, false, method, type, staticusenames, usenames));
            }
            else if (MethodNativeCodeCreator.CheckIsIndexerSetter(method, type, out pinfo)

                     && method.GetParameters().Length == 2
                     )
            {
                //****索引器****
                string testname = GetMethodName(method.Name, false, method, type, staticusenames, usenames);
                if (testname == method.Name)
                {
                    testname = "setThisItem";
                }

                nativefunName = string.Format("{0}_{1}", GetNativeFunctionPart1(type), testname);                 ////GetMethodName( "setThisItem",method,type,staticusenames,usenames));
            }
            else if (MethodNativeCodeCreator.CheckIsSetter(method, type, out pinfo))
            {
                nativefunName = string.Format("{0}_{1}", GetNativeFunctionPart1(type), GetMethodName(method.Name, false, method, type, staticusenames, usenames));
            }
            else
            {
                nativefunName = string.Format("{0}_{1}", GetNativeFunctionPart1(type), GetMethodName(method.Name, false, method, type, staticusenames, usenames));
            }

            if (method.IsStatic)
            {
                nativefunName = "static_" + nativefunName;
            }

            return(nativefunName);
        }
Example #2
0
        /// <summary>
        /// 是否已经手工绑定。
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool IsSkipCreator(Type type)
        {
            if (type == null)
            {
                return(true);
            }

            if (Equals(type, typeof(Type)))
            {
                return(true);
            }


            if (type.IsArray)
            {
                return(IsSkipCreator(type.GetElementType()));
            }

            ASBinCode.RunTimeDataType rttype = MethodNativeCodeCreator.GetAS3Runtimetype(type);
            if (rttype < ASBinCode.RunTimeDataType._OBJECT)
            {
                return(true);
            }

            string fn = type.FullName;

            if (fn == "System.ValueType")
            {
                return(true);
            }

            if (SkipCreateTypes.Contains(fn))
            {
                return(true);
            }



            return(false);
        }
Example #3
0
        public string GetAS3TypeString(Type type, Dictionary <Type, string> typeimports, Type checktype, System.Reflection.MethodBase checkmethod, System.Reflection.ParameterInfo checkparameter)
        {
            if (type.IsByRef)
            {
                if (!typeimports.ContainsValue("import as3runtime.RefOutStore;"))
                {
                    typeimports.Add(typeof(ASRuntime.nativefuncs.linksystem.RefOutStore), "import as3runtime.RefOutStore;");
                }
                return(GetAS3TypeString(type.GetElementType(), typeimports, checktype, checkmethod, checkparameter));
            }

            if (checkparameter != null)
            {
                if (checkmethod.DeclaringType == typeof(System.Collections.IList)
                    ||
                    isMapToInterface(checkmethod, typeof(System.Collections.IList)) != null
                    )
                {
                    if (isMapToInterface(checkmethod, typeof(System.Collections.IList)) != null)
                    {
                        checkmethod = isMapToInterface(checkmethod, typeof(System.Collections.IList));
                    }


                    if (checkmethod.Name == "set_Item" && checkparameter.Name == "value")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "Add")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "Contains")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "IndexOf")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "Insert" && checkparameter.Name == "value")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "Remove")
                    {
                        return("*");
                    }
                }

                if (checkmethod.DeclaringType == typeof(System.Collections.IDictionary)
                    ||
                    isMapToInterface(checkmethod, typeof(System.Collections.IDictionary)) != null
                    )
                {
                    if (isMapToInterface(checkmethod, typeof(System.Collections.IDictionary)) != null)
                    {
                        checkmethod = isMapToInterface(checkmethod, typeof(System.Collections.IDictionary));
                    }

                    if (checkmethod.Name == "get_Item" && checkparameter.Name == "key")
                    {
                        return("Object");
                    }
                    else if (checkmethod.Name == "set_Item" && checkparameter.Name == "value")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "set_Item" && checkparameter.Name == "key")
                    {
                        return("Object");
                    }
                    else if (checkmethod.Name == "Add" && checkparameter.Name == "key")
                    {
                        return("Object");
                    }
                    else if (checkmethod.Name == "Add" && checkparameter.Name == "value")
                    {
                        return("*");
                    }
                    else if (checkmethod.Name == "Contains")
                    {
                        return("Object");
                    }
                    else if (checkmethod.Name == "Remove")
                    {
                        return("Object");
                    }
                }
            }


            if (checktype == typeof(System.Collections.IEnumerator))
            {
                if (checkmethod.Name == "System.Collections.IEnumerator.get_Current"
                    ||
                    checkmethod.Name == "get_Current"
                    )
                {
                    return("*");
                }
            }
            else if (checktype == typeof(System.Collections.IList))
            {
                if (checkmethod.Name == "get_Item"
                    ||
                    checkmethod.Name == "System.Collections.IList.get_Item"
                    )
                {
                    return("*");
                }
            }
            else if (checktype == typeof(System.Collections.IDictionary))
            {
                if (checkmethod.Name == "get_Item"
                    ||
                    checkmethod.Name == "System.Collections.IDictionary.get_Item"
                    )
                {
                    return("*");
                }
            }
            else if (checktype == typeof(System.Collections.IDictionaryEnumerator))
            {
                if (checkmethod.Name == "get_Key"
                    ||
                    isMapToInterface(checkmethod, typeof(System.Collections.IDictionaryEnumerator)) != null
                    )
                {
                    return("Object");
                }
                else if (checkmethod.Name == "get_Value"
                         ||
                         isMapToInterface(checkmethod, typeof(System.Collections.IDictionaryEnumerator)) != null
                         )
                {
                    return("*");
                }
            }


            if (type.Equals(typeof(ASBinCode.RunTimeValueBase)))
            {
                return("*");
            }

            ASBinCode.RunTimeDataType rttype = MethodNativeCodeCreator.GetAS3Runtimetype(type);
            if (rttype == ASBinCode.RunTimeDataType.fun_void)
            {
                return("void");
            }
            else if (rttype == ASBinCode.RunTimeDataType.rt_number)
            {
                return("Number");
            }
            else if (rttype == ASBinCode.RunTimeDataType.rt_int)
            {
                return("int");
            }
            else if (rttype == ASBinCode.RunTimeDataType.rt_uint)
            {
                return("uint");
            }
            else if (rttype == ASBinCode.RunTimeDataType.rt_boolean)
            {
                return("Boolean");
            }
            else if (rttype == ASBinCode.RunTimeDataType.rt_string)
            {
                return("String");
            }



            do
            {
                if (type == typeof(Type))
                {
                    break;
                }

                if (type == typeof(Array) || type.IsArray)
                {
                    if (!typeimports.ContainsValue("import system._Array_;"))
                    {
                        typeimports.Add(typeof(Array), "import system._Array_;");
                    }
                }
                else if (this.type.Namespace != type.Namespace)
                {
                    if (!typeimports.ContainsKey(type))
                    {
                        typeimports.Add(type, "import " + type.Namespace.ToLower() + "." + GetAS3ClassOrInterfaceName(type) + ";");
                    }
                }
            } while (false);


            string name = GetAS3ClassOrInterfaceName(type);

            return(name);
        }
Example #4
0
        /// <summary>
        /// 返回如果在成员中涉及这种类型是否要跳过
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool IsSkipType(Type type, bool includeref = false)
        {
            if (type == null)
            {
                return(true);
            }
            var c = CustomAttributeData.GetCustomAttributes(type);

            foreach (CustomAttributeData item in c)
            {
                if (item.Constructor.DeclaringType == typeof(System.ObsoleteAttribute))
                {
                    return(true);
                }
            }

            //object[] objs = type.GetCustomAttributes(typeof(System.ObsoleteAttribute), false);

            //if (objs.Length > 0)
            //{
            //	return true;
            //}



            if (Equals(type, typeof(Type)))             //Type会转换为Class
            {
                return(false);
            }

            if (type.IsCOMObject)
            {
                return(true);
            }

            if (Equals(type, typeof(Enum)))
            {
                return(true);
            }

            if (type.IsEnum)
            {
                foreach (var item in NotCreateNameSpace)
                {
                    if (type.Namespace == item)
                    {
                        return(true);
                    }
                    if (type.Namespace.StartsWith(item + "."))
                    {
                        return(true);
                    }
                }

                if (NotCreateTypes.Contains(type.FullName))
                {
                    return(true);
                }
                return(false);
            }


            if (type.IsByRef)
            {
                if (!includeref)
                {
                    return(true);
                }
                else if (type.HasElementType)
                {
                    return(IsSkipType(type.GetElementType()));
                }
            }

            if (type.IsNotPublic)
            {
                return(true);
            }

            if (type.IsNested)
            {
                if (IsSkipType(type.DeclaringType))
                {
                    return(true);
                }
            }

            if (type.IsGenericTypeDefinition)
            {
                return(true);
            }
            if (type.IsGenericType && type.IsInterface)
            {
                return(true);
            }

            if (IsDelegate(type))
            {
                //var m = GetDelegateMethodInfo(type);
                //var n=GetSharpTypeName(type);
                //var k = NativeCodeCreatorBase.GetTypeFullName(type);


                var m = GetDelegateMethodInfo(type);
                //***如果该委托包含要跳过的类型,则跳过****
                if (m.IsGenericMethod)
                {
                    return(true);
                }

                if (m.ReturnType.IsGenericTypeDefinition)
                {
                    return(true);
                }

                var rt = MethodNativeCodeCreator.GetAS3Runtimetype(m.ReturnType);
                if (rt > ASBinCode.RunTimeDataType.unknown)
                {
                    if (IsSkipType(m.ReturnType))
                    {
                        return(true);
                    }
                }

                var paras = m.GetParameters();
                foreach (var p in paras)
                {
                    if (p.IsOut)
                    {
                        return(true);
                    }
                    if (p.ParameterType.IsByRef)
                    {
                        return(true);
                    }
                    //if (p.ParameterType.IsGenericType)
                    if (p.ParameterType.IsGenericTypeDefinition)
                    {
                        return(true);
                    }

                    if (p.IsOptional)
                    {
                        if (p.RawDefaultValue != null)
                        {
                            var rrt = MethodNativeCodeCreator.GetAS3Runtimetype(p.ParameterType);
                            if (rrt > ASBinCode.RunTimeDataType.unknown)
                            {
                                return(true);
                            }
                        }
                    }

                    if (IsSkipType(p.ParameterType))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            //if (type.IsGenericType)
            //{
            //	return true;
            //}

            if (type.IsArray)
            {
                return(IsSkipType(type.GetElementType()));
            }

            foreach (var item in NotCreateNameSpace)
            {
                if (type.Namespace == item)
                {
                    return(true);
                }
                if (type.Namespace.StartsWith(item + "."))
                {
                    return(true);
                }
            }

            if (NotCreateTypes.Contains(type.FullName))
            {
                return(true);
            }



            if (Equals(type, typeof(TypedReference)))
            {
                return(true);
            }

            if (type.BaseType != null)
            {
                return(IsSkipType(type.BaseType));
            }

            return(false);
        }
        public InterfaceCreator(Type interfacetype, string as3apidocpath, string csharpnativecodepath,
                                Dictionary <TypeKey, CreatorBase> typeCreators,
                                string linkcodenamespace
                                ) : base(interfacetype, as3apidocpath, csharpnativecodepath, linkcodenamespace)
        {
            if (!interfacetype.IsInterface)
            {
                throw new ArgumentException("类型不是接口");
            }

            if (interfacetype.IsGenericType)
            {
                throw new ArgumentException("不支持泛型接口");
            }
            if (IsSkipCreator(interfacetype)
                )
            {
                throw new ArgumentException("接口已配置为跳过");
            }

            if (IsSkipType(interfacetype))
            {
                throw new ArgumentException("接口已配置为不生成");
            }

            name = GetAS3ClassOrInterfaceName(interfacetype);

            var exts = GetExtendInterfaces(interfacetype);

            foreach (var item in exts)
            {
                if (!typeCreators.ContainsKey(new TypeKey(item)) && !IsSkipCreator(item) && !IsSkipType(item))
                {
                    typeCreators.Add(new TypeKey(item), null); typeCreators[new TypeKey(item)] = new InterfaceCreator(item, as3apidocpath, csharpnativecodepath, typeCreators, linkcodenamespace);
                }
            }

            if (exts.Count > 1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(interfacetype + "检查到接口多继承,这里使用第一个");
                Console.ResetColor();
                super = exts[0];
            }
            else if (exts.Count == 1)
            {
                super = exts[0];
            }

            //****分析引用到的类型****
            var methods = interfacetype.GetMethods();

            foreach (var item in methods)
            {
                if (IsObsolete(item, type))
                {
                    continue;
                }

                if (item.IsGenericMethod)
                {
                    continue;
                }

                if (item.ReturnType.IsGenericTypeDefinition)
                {
                    continue;
                }

                if (IsSkipMember(item))
                {
                    continue;
                }

                var rt = MethodNativeCodeCreator.GetAS3Runtimetype(item.ReturnType);
                if (rt > ASBinCode.RunTimeDataType.unknown)
                {
                    if (IsSkipType(item.ReturnType))
                    {
                        continue;
                    }

                    MakeCreator(item.ReturnType, typeCreators);
                }
                bool hasoptional = false;
                bool parapass    = true;
                var  paras       = item.GetParameters();
                foreach (var p in paras)
                {
                    if (p.IsOut)
                    {
                        parapass = false;
                        break;
                    }
                    if (p.ParameterType.IsByRef)
                    {
                        parapass = false;
                        break;
                    }

                    if (p.ParameterType.IsGenericTypeDefinition)
                    {
                        parapass = false;
                        break;
                    }

                    if (p.IsOptional)
                    {
                        hasoptional = true;
                        if (p.RawDefaultValue != null)
                        {
                            var rrt = MethodNativeCodeCreator.GetAS3Runtimetype(p.ParameterType);
                            if (rrt > ASBinCode.RunTimeDataType.unknown)
                            {
                                parapass = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (hasoptional)
                        {
                            parapass = false;
                            break;
                        }
                    }

                    if (IsSkipType(p.ParameterType, true))
                    {
                        parapass = false;
                        break;
                    }

                    var pt = MethodNativeCodeCreator.GetAS3Runtimetype(p.ParameterType);
                    if (pt > ASBinCode.RunTimeDataType.unknown)
                    {
                        var mt = p.ParameterType;
                        if (p.ParameterType.IsByRef)
                        {
                            mt = p.ParameterType.GetElementType();
                        }
                        MakeCreator(mt, typeCreators);
                    }
                }

                if (parapass)
                {
                    methodlist.Add(item);
                }
            }
        }
        public override string Create()
        {
            Dictionary <Type, string> typeimports = new Dictionary <Type, string>();

            StringBuilder nativefunc = new StringBuilder();

            //GenNativeFuncImport(nativefunc);
            GenNativeFuncNameSpaceAndClass(nativefunc);

            BeginRegFunction(nativefunc);

            List <string> regfunctions      = new List <string>();
            List <string> nativefuncClasses = new List <string>();



            StringBuilder as3api = new StringBuilder();

            GenAS3FileHead(as3api);

            as3api.AppendLine("@imports");
            as3api.AppendLine();

            as3api.AppendFormat("\t[link_system_interface({0})]", GetCreatorNativeFuncName(type));
            as3api.AppendLine();
            as3api.AppendFormat("\tpublic interface {0}", name);


            regfunctions.Add(
                "\t\t\tbin.regNativeFunction(LinkSystem_Buildin.getCreator(\"" + GetCreatorNativeFuncName(type) + "\", default(" + NativeCodeCreatorBase.GetTypeFullName(type) + ")));");


            if (super != null)
            {
                as3api.AppendFormat(" extends {0}", GetAS3TypeString(super, typeimports, null, null, null));
            }

            as3api.AppendLine();
            as3api.AppendLine("\t{");

            bool existsindexgetter = false;
            bool existsindexsetter = false;

            foreach (var method in methodlist)
            {
                //if (method.IsGenericMethod)
                //{
                //	Console.WriteLine("跳过泛型方法"+method.ToString());

                //	continue;
                //}

                //if (IsSkipType(method.ReturnType))
                //{
                //	Console.WriteLine(method.ToString() + "返回类型被配置为需要跳过");
                //	continue;
                //}


                var paras = method.GetParameters();

                //bool parachecked = true;
                //foreach (var para in paras)
                //{
                //	if (para.IsOut)
                //	{
                //		Console.WriteLine(method.ToString()+"参数"+ para.Position+" " +para+ "为out,跳过");
                //		parachecked=false;
                //		break;
                //	}
                //	if (para.ParameterType.IsByRef)
                //	{
                //		Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "为byref,跳过");
                //		parachecked = false;
                //		break;
                //	}
                //	if (para.ParameterType.IsGenericType)
                //	{
                //		Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "为泛型,跳过");
                //		parachecked = false;
                //		break;
                //	}

                //	if (para.IsOptional)
                //	{
                //		if (para.RawDefaultValue != null)
                //		{
                //			var rt = MethodNativeCodeCreator.GetAS3Runtimetype(para.ParameterType);
                //			if (rt > ASBinCode.RunTimeDataType.unknown)
                //			{
                //				Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "为可选,并且默认值不是基本类型");
                //				parachecked = false;
                //				break;
                //			}
                //		}
                //	}

                //	if (IsSkipType(para.ParameterType))
                //	{
                //		Console.WriteLine(method.ToString() + "参数" + para.Position + " " + para + "被配置为需要跳过");
                //		parachecked = false;
                //		break;
                //	}

                //}

                //if (!parachecked)
                //{
                //	continue;
                //}

                if (isMethodSkip(method))
                {
                    Console.WriteLine(method.ToString() + "有参数或返回值被配置为需要跳过");
                    continue;
                }
                string returntype = GetAS3TypeString(method.ReturnType, typeimports, type, method, null);

                string nativefunName = GetMethodNativeFunctionName(method, type, null, null);

                System.Reflection.PropertyInfo pinfo;
                if (MethodNativeCodeCreator.CheckIsIndexerGetter(method, type, out pinfo) && !existsindexgetter)
                {
                    existsindexgetter = true;
                    //****索引器****
                    as3api.Append("\t\t");
                    as3api.AppendLine("[get_this_item];");


                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}];", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    var name = GetMethodName(method.Name, method, type, null, null);
                    as3api.Append("function " + name);
                }
                else if (MethodNativeCodeCreator.CheckIsGetter(method, type, out pinfo))
                {
                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}]", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    as3api.Append("function get ");
                    as3api.Append(GetMethodName(pinfo.Name, method, type, null, null));
                }
                else if (MethodNativeCodeCreator.CheckIsIndexerSetter(method, type, out pinfo) && !existsindexsetter)
                {
                    existsindexsetter = true;
                    //****索引器****
                    as3api.Append("\t\t");
                    as3api.AppendLine("[set_this_item];");

                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}];", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    var name = GetMethodName(method.Name, method, type, null, null);
                    as3api.Append("function " + name);

                    var temp = paras[0];
                    paras[0] = paras[1];
                    paras[1] = temp;
                }
                else if (MethodNativeCodeCreator.CheckIsSetter(method, type, out pinfo))
                {
                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}]", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    as3api.Append("function set ");
                    as3api.Append(GetMethodName(pinfo.Name, method, type, null, null));
                }
                else
                {
                    as3api.Append("\t\t");
                    as3api.AppendFormat("[native,{0}]", nativefunName);
                    as3api.AppendLine();

                    as3api.Append("\t\t");
                    as3api.Append("function ");
                    as3api.Append(GetMethodName(method.Name, method, type, null, null));
                }

                as3api.Append("(");

                for (int i = 0; i < paras.Length; i++)
                {
                    var para = paras[i];
                    as3api.Append(para.Name);
                    if (as3keywords.ContainsKey(para.Name))
                    {
                        as3api.Append("_");
                    }
                    as3api.Append(":");
                    as3api.Append(GetAS3TypeString(para.ParameterType, typeimports, null, method, para));

                    if (para.IsOptional)
                    {
                        as3api.Append("=");

                        if (para.RawDefaultValue != null)
                        {
                            var rt = MethodNativeCodeCreator.GetAS3Runtimetype(para.ParameterType);
                            if (rt == ASBinCode.RunTimeDataType.rt_string)
                            {
                                string str = para.RawDefaultValue.ToString();
                                str = str.Replace("\\", "\\\\");
                                str = str.Replace("\"", "\\\"");

                                as3api.Append("\"" + str + "\"");
                            }
                            else
                            {
                                as3api.Append(para.RawDefaultValue.ToString());
                            }
                        }
                        else
                        {
                            as3api.Append("null");
                        }
                    }

                    if (i < paras.Length - 1)
                    {
                        as3api.Append(",");
                    }
                }

                as3api.Append(")");
                as3api.Append(":");
                as3api.Append(returntype);
                as3api.AppendLine(";");
                as3api.AppendLine();

                //***编写方法的本地代码***


                //****检测是否可以用反射。***
                bool checkreflection = true;

                if (method.ReturnType.IsByRef)
                {
                    checkreflection = false;
                }


                var param = method.GetParameters();
                foreach (var item in param)
                {
                    if (item.ParameterType.IsByRef)
                    {
                        checkreflection = false;
                    }
                    if (item.ParameterType.Equals(typeof(Type)))
                    {
                        checkreflection = false;
                    }
                    //if (item.ParameterType.IsValueType)
                    //	checkreflection = false;
                }
                if (method.ReturnType.Equals(typeof(Type)))
                {
                    checkreflection = false;
                }

                if (checkreflection && false)
                {
                    bool needswap = false;
                    System.Reflection.PropertyInfo propertyInfo;
                    if (MethodNativeCodeCreator.CheckIsIndexerSetter((System.Reflection.MethodInfo)method, method.DeclaringType, out propertyInfo) && param.Length == 2)
                    {
                        needswap = true;
                    }

                    string returntypestr;
                    if (method.ReturnType.IsValueType && !method.ReturnType.Equals(typeof(void)))
                    {
                        returntypestr = NativeCodeCreatorBase.GetTypeFullName(method.ReturnType);
                    }
                    else
                    {
                        returntypestr = "object";
                    }
                    string regrefl = string.Format("\t\t\tbin.regNativeFunction(new ReflectionInvokeNativeFunction<" + returntypestr + ">("
                                                   + (method.IsStatic ? "true" : "false") + ","
                                                   + (needswap ? "true" : "false") + ","
                                                   + param.Length + ",\"{0}\",\"{1}\",", nativefunName, method.Name);
                    regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(method.ReturnType) + " ,\n\t\t\t\t";

                    regrefl += "new int[]";
                    regrefl += "{";

                    if (needswap)
                    {
                        regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(param[1].ParameterType);
                        regrefl += ",\n\t\t\t\t";
                        regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(param[0].ParameterType);
                    }
                    else
                    {
                        for (int i = 0; i < param.Length; i++)
                        {
                            regrefl += GetReflectionInvokeNativeFunctionTypeCodeString(param[i].ParameterType);
                            if (i < param.Length - 1)
                            {
                                regrefl += ",\n\t\t\t\t";
                            }
                        }
                    }
                    regrefl += "}))";

                    regrefl += ";";

                    regfunctions.Add(regrefl);
                }
                else
                {
                    regfunctions.Add(string.Format("\t\t\tbin.regNativeFunction(\"{0}\",\"{1}\");", LinkCodeNampScapePart + nativefunName, nativefunName));
                    MethodNativeCodeCreator mc = new MethodNativeCodeCreator(nativefunName, method, type);
                    nativefuncClasses.Add(mc.GetCode());
                }
            }

            as3api.AppendLine("\t}");

            EndAS3File(as3api);

            string imports = string.Empty;

            foreach (var item in typeimports.Values)
            {
                imports += "\t" + item + "\n";
            }
            as3api.Replace("@imports", imports);


            for (int i = 0; i < regfunctions.Count; i++)
            {
                nativefunc.AppendLine(regfunctions[i]);
            }

            EndRegFunction(nativefunc);

            for (int i = 0; i < nativefuncClasses.Count; i++)
            {
                nativefunc.AppendLine(nativefuncClasses[i]);
            }

            EndNativeFuncClass(nativefunc);



            //Console.WriteLine(as3api.ToString());
            //Console.WriteLine(nativefunc.ToString());

            string as3file       = as3apidocpath + "/" + GetPackageName(type).Replace(".", "/") + "/" + name + ".as";
            string nativefunfile = csharpnativecodepath + "/" + GetNativeFunctionClassName(type) + ".cs";

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(as3file));
            System.IO.File.WriteAllText(as3file, as3api.ToString());

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(nativefunfile));

            StringBuilder usingcode = new StringBuilder();

            GenNativeFuncImport(usingcode);

            System.IO.File.WriteAllText(nativefunfile, usingcode.ToString() + nativefunc.ToString());

            return(nativefunc.ToString());
        }
        public static bool isMethodSkip(System.Reflection.MethodInfo method)
        {
            var item = method;

            if (IsObsolete(item, method.DeclaringType))
            {
                return(true);
            }

            if (item.IsGenericMethod)
            {
                return(true);
            }

            if (item.ReturnType.IsGenericTypeDefinition)
            {
                return(true);
            }

            if (IsSkipMember(item))
            {
                return(true);
            }

            var rt = MethodNativeCodeCreator.GetAS3Runtimetype(item.ReturnType);

            if (rt > ASBinCode.RunTimeDataType.unknown)
            {
                if (IsSkipType(method.ReturnType))
                {
                    return(true);
                }
            }

            bool hasoptional = false;
            var  paras       = item.GetParameters();

            foreach (var p in paras)
            {
                if (p.IsOut)
                {
                    return(true);
                }
                if (p.ParameterType.IsByRef)
                {
                    return(true);
                }

                if (p.ParameterType.IsGenericTypeDefinition)
                {
                    return(true);
                }

                if (p.IsOptional)
                {
                    hasoptional = true;
                    if (p.RawDefaultValue != null)
                    {
                        var rrt = MethodNativeCodeCreator.GetAS3Runtimetype(p.ParameterType);
                        if (rrt > ASBinCode.RunTimeDataType.unknown)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    if (hasoptional)
                    {
                        return(true);
                    }
                }

                if (IsSkipType(p.ParameterType, true))
                {
                    return(true);
                }
            }

            return(false);
            //if (IsObsolete(method,method.DeclaringType))
            //{
            //	return true;
            //}

            //if (method.IsGenericMethod)
            //{
            //	return true;
            //}

            //if (IsSkipType(method.ReturnType))
            //{
            //	return true;
            //}

            //var paras = method.GetParameters();
            //foreach (var para in paras)
            //{
            //	if (para.IsOut)
            //	{
            //		return true;
            //	}
            //	if (para.ParameterType.IsByRef)
            //	{
            //		return true;
            //	}
            //	if (para.ParameterType.IsGenericType)
            //	{
            //		return true;
            //	}

            //	if (para.IsOptional)
            //	{
            //		if (para.RawDefaultValue != null)
            //		{
            //			var rt = MethodNativeCodeCreator.GetAS3Runtimetype(para.ParameterType);
            //			if (rt > ASBinCode.RunTimeDataType.unknown)
            //			{
            //				return true;
            //			}
            //		}
            //	}

            //	if (IsSkipType(para.ParameterType))
            //	{
            //		return true;
            //	}

            //}

            //return false;
        }
        public string GetPublicProtectedCode()
        {
            var paras     = method.GetParameters();
            int paracount = paras.Length;



            string code = "";

            if (!method.IsPublic)
            {
                //***将受保护的方法公开***
                code += "\t\t\tpublic ";

                if (method.ReturnType == typeof(void))
                {
                    code += "void";
                }
                else
                {
                    code += GetTypeFullName(method.ReturnType);
                }

                code += " " + method.Name + "___Adapter";

                code += "(";
                foreach (var item in paras)
                {
                    code += GetTypeFullName(item.ParameterType) + " ";
                    code += item.Name;

                    if (item != paras[paras.Length - 1])
                    {
                        code += ",";
                    }
                }
                code += ")";
                code += "\n";

                code += "\t\t\t{\n";

                code += "\t\t\t\t{\n";

                if (method.ReturnType != typeof(void))
                {
                    code += "\t\t\t\t\treturn ";
                }
                if (!method.IsSpecialName)
                {
                    code += "this." + method.Name + "(";

                    foreach (var item in paras)
                    {
                        code += item.Name;
                        if (item != paras[paras.Length - 1])
                        {
                            code += ",";
                        }
                    }


                    code += ");\n";
                }
                else
                {
                    PropertyInfo p;
                    MethodNativeCodeCreator.CheckIsGetter(method, methodAtType, out p, !method.IsPublic);

                    code += "this." + p.Name + ";\n";
                }


                code += "\t\t\t\t}\n";


                code += "\t\t\t}\n";
            }

            return(code);
        }
        public string GetCode()
        {
            var paras     = method.GetParameters();
            int paracount = paras.Length;



            string code = "";

            string as3functionvariable   = "_as3function_" + vmidx;
            string as3functionvariableid = "_as3functionId_" + vmidx;

            if (!method.IsPublic)
            {
                //***将受保护的方法公开***
                code += "\t\t\tpublic ";

                if (method.ReturnType == typeof(void))
                {
                    code += "void";
                }
                else
                {
                    code += GetTypeFullName(method.ReturnType);
                }

                code += " " + method.Name + "___Adapter";

                code += "(";
                foreach (var item in paras)
                {
                    code += GetTypeFullName(item.ParameterType) + " ";
                    code += item.Name;

                    if (item != paras[paras.Length - 1])
                    {
                        code += ",";
                    }
                }
                code += ")";
                code += "\n";

                code += "\t\t\t{\n";

                code += "\t\t\t\t{\n";

                if (method.ReturnType != typeof(void))
                {
                    code += "\t\t\t\t\treturn ";
                }
                if (!method.IsSpecialName)
                {
                    code += "this." + method.Name + "(";

                    foreach (var item in paras)
                    {
                        code += item.Name;
                        if (item != paras[paras.Length - 1])
                        {
                            code += ",";
                        }
                    }


                    code += ");\n";
                }
                else
                {
                    PropertyInfo p;
                    MethodNativeCodeCreator.CheckIsGetter(method, methodAtType, out p, !method.IsPublic);

                    code += "this." + p.Name + ";\n";
                }


                code += "\t\t\t\t}\n";


                code += "\t\t\t}\n";
            }



            if (method.IsPublic)
            {
                code += "\t\t\tprivate ASBinCode.rtData.rtFunction " + as3functionvariable + ";\n";
                code += "\t\t\tprivate int " + as3functionvariableid + " =-1;\n";

                code += "\t\t\t";

                code += "public override ";
            }
            else
            {
                if (method.IsAbstract || method.IsVirtual)
                {
                    code += "\t\t\tprivate ASBinCode.rtData.rtFunction " + as3functionvariable + ";\n";
                    code += "\t\t\tprivate int " + as3functionvariableid + " =-1;\n";

                    code += "\t\t\t";

                    code += "protected override ";
                }
                else
                {
                    return(code);
                }
            }

            if (!method.IsSpecialName)
            {
                if (method.ReturnType == typeof(void))
                {
                    code += "void";
                }
                else
                {
                    code += GetTypeFullName(method.ReturnType);
                }

                code += " " + method.Name;

                code += "(";
                foreach (var item in paras)
                {
                    code += GetTypeFullName(item.ParameterType) + " ";
                    code += item.Name;

                    if (item != paras[paras.Length - 1])
                    {
                        code += ",";
                    }
                }
                code += ")";
                code += "\n";
            }
            else
            {
                PropertyInfo p;
                MethodNativeCodeCreator.CheckIsGetter(method, methodAtType, out p, !method.IsPublic);



                code += GetTypeFullName(method.ReturnType);
                code += " ";

                code += p.Name;
                code += "\n\t\t\t{";
                code += "\n\t\t\t\tget";
                code += "\n";
            }

            code += "\t\t\t{\n";


            string prepareAS3Method = @"
				if (player == null && Player._calling_icrossextendadapter_ctor_player != null)
				{
					SetAS3RuntimeEnvironment(Player._calling_icrossextendadapter_ctor_player, Player._making_icrossextendadapter_obj.value._class, Player._making_icrossextendadapter_obj);
					((LinkObj<object>)(Player._making_icrossextendadapter_obj.value)).value = this;
				}

				if ([as3functionvariable] == null)
					[as3functionvariable] = (ASBinCode.rtData.rtFunction)player.getMethod(bindAS3Object, ""[as3methodname]"");
				if ([as3functionvariableid] == -1)
				{
					[as3functionvariableid] = ((ClassMethodGetter)typeclass.getBaseLinkSystemClass().classMembers.FindByName(""[as3methodname]"").bindField).functionId;
				}
";

            code += prepareAS3Method.Replace("[as3functionvariable]", as3functionvariable).Replace("[as3methodname]", classname).Replace("[as3functionvariableid]", as3functionvariableid);

            if (!method.IsAbstract)
            {
                string invokesupercondition = @"
				if ([as3functionvariable] != null &&
				(player == null || (player != null && NativeConstParameterFunction.checkToken(
				new NativeConstParameterFunction.ExecuteToken(
				player.ExecuteToken.tokenid, [as3functionvariableid]
				)
				))
				)
				)
";

                code += invokesupercondition.Replace("[as3functionvariable]", as3functionvariable).Replace("[as3functionvariableid]", as3functionvariableid);

                code += "\t\t\t\t{\n";

                if (method.ReturnType != typeof(void))
                {
                    code += "\t\t\t\t\treturn ";
                }
                if (!method.IsSpecialName)
                {
                    code += "base." + method.Name + "(";

                    foreach (var item in paras)
                    {
                        code += item.Name;
                        if (item != paras[paras.Length - 1])
                        {
                            code += ",";
                        }
                    }


                    code += ");\n";
                }
                else
                {
                    PropertyInfo p;
                    MethodNativeCodeCreator.CheckIsGetter(method, methodAtType, out p, !method.IsPublic);

                    code += "base." + p.Name + ";\n";
                }

                code += "\t\t\t\t}\n";

                code += "\t\t\t\telse\n";
            }
            else
            {
                string invokesupercondition = @"
				if ([as3functionvariable] != null &&
					(player == null || (player != null && NativeConstParameterFunction.checkToken(
					new NativeConstParameterFunction.ExecuteToken(
					player.ExecuteToken.tokenid, [as3functionvariableid]
					)
					))
				))
				{
					throw new ASRunTimeException(""不能调用抽象方法"",new Exception());
				}
				else
";
                code += invokesupercondition.Replace("[as3functionvariable]", as3functionvariable).Replace("[as3functionvariableid]", as3functionvariableid);
            }

            code += "\t\t\t\t{\n";


            string invoke = "player.InvokeFunction";

            invoke += "(";
            invoke += as3functionvariable + ",";
            invoke += paracount + ",";

            for (int i = 0; i < 5; i++)
            {
                if (i < paracount)
                {
                    invoke += paras[i].Name + ",";
                }
                else
                {
                    invoke += "null,";
                }
            }
            if (paracount > 5)
            {
                invoke += "new object[]{";

                for (int i = 5; i < paracount; i++)
                {
                    invoke += paras[i].Name;
                    if (i < paracount - 1)
                    {
                        invoke += ",";
                    }
                }

                invoke += "}";
                //new object[] { }
            }
            else
            {
                invoke += "null";
            }

            invoke += ");\n";


            if (method.ReturnType != typeof(void))
            {
                code += "\t\t\t\t\treturn (" + GetTypeFullName(method.ReturnType) + ")";
            }
            else
            {
                code += "\t\t\t\t\t";
            }

            code += invoke;


            code += "\t\t\t\t}\n";


            code += "\t\t\t}\n";

            if (method.IsSpecialName)
            {
                code += "\t\t\t}\n";
            }

            return(code);
        }
Example #10
0
        public string GetCode()
        {
            var paras = method.GetParameters();


            PropertyInfo propertyInfo;

            if (MethodNativeCodeCreator.CheckIsIndexerSetter((MethodInfo)method, method.DeclaringType, out propertyInfo) && paras.Length == 2)
            {
                var temp = paras[0];
                paras[0] = new myparainfo(paras[1], 0);
                paras[1] = new myparainfo(temp, 1);
            }


            int  paracount = paras.Length;
            bool hasref    = false;

            foreach (var item in paras)
            {
                if (item.ParameterType.IsByRef)
                {
                    paracount += 1;
                    hasref     = true;
                    break;
                }
            }

            string funccode = Properties.Resources.StaticMethodFunc;

            funccode = funccode.Replace("[classname]", classname);
            funccode = funccode.Replace("[paracount]", paracount.ToString());

            string pushparas = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var para = paras[i];

                pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(para.ParameterType));
            }

            if (hasref)
            {
                pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(typeof(ASRuntime.nativefuncs.linksystem.RefOutStore)));
            }

            funccode = funccode.Replace("[pushparas]", pushparas);
            funccode = funccode.Replace("[returntype]", GetAS3RuntimeTypeString(method.ReturnType));

            string loadargs = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var argement = paras[i];

                loadargs = loadargs + GetLoadArgementString(argement);
                loadargs = loadargs + "\n";
            }
            if (hasref)
            {
                loadargs = loadargs + GetLoadArgementString(typeof(ASRuntime.nativefuncs.linksystem.RefOutStore), paras.Length);
                loadargs = loadargs + "\n";
            }

            funccode = funccode.Replace("[loadargement]", loadargs);

            var rettype = GetAS3Runtimetype(method.ReturnType);

            if (rettype == ASBinCode.RunTimeDataType.fun_void)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = GetTypeFullName(methodAtType);
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t;\n";
                storeresult  = storeresult + "\t\t\t\t\treturnSlot.directSet(ASBinCode.rtData.rtUndefined.undefined);";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_int)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "int _result_ = (int)(" + GetTypeFullName(methodAtType);
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_uint)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "uint _result_ = (uint)(" + GetTypeFullName(methodAtType);
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_number)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "double _result_ = (double)(" + GetTypeFullName(methodAtType);
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_string)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "string _result_ = (string)(" + GetTypeFullName(methodAtType);
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_boolean)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "bool _result_ = " + GetTypeFullName(methodAtType);
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\tif(_result_)\n";
                storeresult += "\t\t\t\t\t{\n";
                storeresult += "\t\t\t\t\t\treturnSlot.setValue(ASBinCode.rtData.rtBoolean.True);\n";
                storeresult += "\t\t\t\t\t}\n";
                storeresult += "\t\t\t\t\telse\n";
                storeresult += "\t\t\t\t\t{\n";
                storeresult += "\t\t\t\t\t\treturnSlot.setValue(ASBinCode.rtData.rtBoolean.False);\n";
                storeresult += "\t\t\t\t\t}\n";


                funccode = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype > ASBinCode.RunTimeDataType.unknown)
            {
                if (method.ReturnType.IsValueType)
                {
                    string storeresult = string.Empty;
                    //***调用方法****
                    storeresult = GetTypeFullName(method.ReturnType) + " _result_ = " + GetTypeFullName(methodAtType);
                    storeresult = GetInvokeMethodString(storeresult, paras);

                    storeresult += "\t\t\t\t\t;\n";
                    //storeresult += "\t\t\t\t\tstackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_, functionDefine.signature.returnType, returnSlot, bin, stackframe.player);";
                    storeresult += "\t\t\t\t\t((StackSlot)returnSlot).setLinkObjectValue(bin.getClassByRunTimeDataType(functionDefine.signature.returnType), stackframe.player, _result_);";

                    funccode = funccode.Replace("[storeresult]", storeresult);
                }
                else
                {
                    string storeresult = string.Empty;
                    //***调用方法****
                    storeresult = "object _result_ = " + GetTypeFullName(methodAtType);
                    storeresult = GetInvokeMethodString(storeresult, paras);

                    storeresult += "\t\t\t\t\t;\n";
                    storeresult += "\t\t\t\t\tstackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_, functionDefine.signature.returnType, returnSlot, bin, stackframe.player);";
                    funccode     = funccode.Replace("[storeresult]", storeresult);
                }
            }
            else
            {
                funccode = funccode.Replace("[storeresult]", "代码生成错误,不能转换返回类型");
            }


            if (!hasref)
            {
                funccode = funccode.Replace("[storeref]", string.Empty);
            }
            else
            {
                string storetemplate = @"
					if (arg[storeidx] != null)
					{
						arg[storeidx].SetValue(functionDefine.signature.parameters[[argidx]].name, arg[argidx]);
					}
";

                string toreplace = @"
					if (arg[storeidx] != null)
					{
						arg[storeidx].Clear();
					}
";;
                toreplace = toreplace.Replace("[storeidx]", paras.Length.ToString());
                for (int i = 0; i < paras.Length; i++)
                {
                    if (paras[i].ParameterType.IsByRef)
                    {
                        toreplace += storetemplate.Replace("[storeidx]", paras.Length.ToString()).Replace("[argidx]", i.ToString());
                    }
                }

                funccode = funccode.Replace("[storeref]", toreplace);
            }

            return(funccode);
        }
Example #11
0
        public string GetCode()
        {
            var paras = method.GetParameters();

            bool ismakedelegate = true;

            if (CreatorBase.IsDelegate(methodAtType))
            {
                ismakedelegate = false;
            }

            if (method is MethodInfo)
            {
                PropertyInfo propertyInfo;
                if (MethodNativeCodeCreator.CheckIsIndexerSetter((MethodInfo)method, method.DeclaringType, out propertyInfo) && paras.Length == 2)
                {
                    var temp = paras[0];
                    paras[0] = new myparainfo(paras[1], 0);
                    paras[1] = new myparainfo(temp, 1);


                    ismakedelegate = false;
                }

                if (MethodNativeCodeCreator.CheckIsIndexerGetter((MethodInfo)method, method.DeclaringType, out propertyInfo))
                {
                    ismakedelegate = false;
                }
                if (MethodNativeCodeCreator.CheckIsSetter((MethodInfo)method, method.DeclaringType, out propertyInfo))
                {
                    ismakedelegate = false;
                }
                if (MethodNativeCodeCreator.CheckIsGetter((MethodInfo)method, method.DeclaringType, out propertyInfo))
                {
                    ismakedelegate = false;
                }

                if (method.IsSpecialName)
                {
                    ismakedelegate = false;
                }

                if (method.IsGenericMethodDefinition)
                {
                    ismakedelegate = false;
                }
            }



            int  paracount = paras.Length;
            bool hasref    = false;

            foreach (var item in paras)
            {
                if (item.ParameterType.IsByRef)
                {
                    paracount += 1;
                    hasref     = true;
                    break;
                }
            }

            string funccode;

            if (ismakedelegate)
            {
                funccode = Properties.Resources.IMethodGetterMethodFunc;
            }
            else
            {
                funccode = Properties.Resources.MethodFunc;
            }



            funccode = funccode.Replace("[classname]", classname);
            funccode = funccode.Replace("[paracount]", paracount.ToString());

            string pushparas = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var para = paras[i];

                pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(para.ParameterType));
            }

            if (hasref)
            {
                pushparas = pushparas + "\t\t\t\t" + string.Format("para.Add({0});\n", GetAS3RuntimeTypeString(typeof(ASRuntime.nativefuncs.linksystem.RefOutStore)));
            }


            funccode = funccode.Replace("[pushparas]", pushparas);
            funccode = funccode.Replace("[returntype]", GetAS3RuntimeTypeString(method.ReturnType));

            if (methodAtType.IsValueType)
            {
                string loadthis = Properties.Resources.LoadStructThis;
                loadthis = loadthis.Replace("[thisObjtype]", GetTypeFullName(methodAtType));
                funccode = funccode.Replace("[loadthis]", loadthis);
            }
            else
            {
                string loadthis = Properties.Resources.LoadThis;
                loadthis = loadthis.Replace("[thisObjtype]", GetTypeFullName(methodAtType));
                funccode = funccode.Replace("[loadthis]", loadthis);
            }


            string loadargs = string.Empty;

            for (int i = 0; i < paras.Length; i++)
            {
                var argement = paras[i];

                loadargs = loadargs + GetLoadArgementString(argement);
                loadargs = loadargs + "\n";
            }
            if (hasref)
            {
                loadargs = loadargs + GetLoadArgementString(typeof(ASRuntime.nativefuncs.linksystem.RefOutStore), paras.Length);
                loadargs = loadargs + "\n";
            }


            funccode = funccode.Replace("[loadargement]", loadargs);

            var rettype = GetAS3Runtimetype(method.ReturnType);

            if (rettype == ASBinCode.RunTimeDataType.fun_void)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "_this";
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t;\n";
                storeresult  = storeresult + "\t\t\t\t\treturnSlot.directSet(ASBinCode.rtData.rtUndefined.undefined);";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_int)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "int _result_ = (int)(_this";
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_uint)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "uint _result_ = (uint)(_this";
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_number)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "double _result_ = (double)(_this";
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_string)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "string _result_ = (string)(_this";
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t)\n";
                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\treturnSlot.setValue(_result_);\n";
                funccode     = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype == ASBinCode.RunTimeDataType.rt_boolean)
            {
                string storeresult = string.Empty;
                //***调用方法****
                storeresult = "bool _result_ = _this";
                storeresult = GetInvokeMethodString(storeresult, paras);

                storeresult += "\t\t\t\t\t;\n";
                storeresult += "\t\t\t\t\tif(_result_)\n";
                storeresult += "\t\t\t\t\t{\n";
                storeresult += "\t\t\t\t\t\treturnSlot.setValue(ASBinCode.rtData.rtBoolean.True);\n";
                storeresult += "\t\t\t\t\t}\n";
                storeresult += "\t\t\t\t\telse\n";
                storeresult += "\t\t\t\t\t{\n";
                storeresult += "\t\t\t\t\t\treturnSlot.setValue(ASBinCode.rtData.rtBoolean.False);\n";
                storeresult += "\t\t\t\t\t}\n";


                funccode = funccode.Replace("[storeresult]", storeresult);
            }
            else if (rettype > ASBinCode.RunTimeDataType.unknown)
            {
                if (method.ReturnType.IsValueType)
                {
                    string storeresult = string.Empty;
                    //***调用方法****
                    storeresult = GetTypeFullName(method.ReturnType) + " _result_ = _this";
                    storeresult = GetInvokeMethodString(storeresult, paras);

                    storeresult += "\t\t\t\t\t;\n";
                    //storeresult += "\t\t\t\t\tstackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_, functionDefine.signature.returnType, returnSlot, bin, stackframe.player);";
                    storeresult += "\t\t\t\t\t((StackSlot)returnSlot).setLinkObjectValue(bin.getClassByRunTimeDataType(functionDefine.signature.returnType), stackframe.player, _result_);";

                    funccode = funccode.Replace("[storeresult]", storeresult);
                }
                else
                {
                    string storeresult = string.Empty;
                    //***调用方法****
                    storeresult = "object _result_ = _this";
                    storeresult = GetInvokeMethodString(storeresult, paras);

                    storeresult += "\t\t\t\t\t;\n";
                    storeresult += "\t\t\t\t\tstackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_, functionDefine.signature.returnType, returnSlot, bin, stackframe.player);";
                    funccode     = funccode.Replace("[storeresult]", storeresult);
                }
            }
            else
            {
                funccode = funccode.Replace("[storeresult]", "代码生成错误,不能转换返回类型");
            }

            if (methodAtType.IsValueType)             //结构体,需要重新赋值回去
            {
                string replacethis = "((LinkObj<" + GetTypeFullName(methodAtType) + ">)((ASBinCode.rtData.rtObjectBase) thisObj).value).value = _this;";
                funccode = funccode.Replace("[replacethis]", replacethis);
            }
            else
            {
                funccode = funccode.Replace("[replacethis]", string.Empty);
            }


            if (!hasref)
            {
                funccode = funccode.Replace("[storeref]", string.Empty);
            }
            else
            {
                string storetemplate = @"
					if (arg[storeidx] != null)
					{
						arg[storeidx].SetValue(functionDefine.signature.parameters[[argidx]].name, arg[argidx]);
					}
";

                string toreplace = @"
					if (arg[storeidx] != null)
					{
						arg[storeidx].Clear();
					}
";;
                toreplace = toreplace.Replace("[storeidx]", paras.Length.ToString());


                for (int i = 0; i < paras.Length; i++)
                {
                    if (paras[i].ParameterType.IsByRef)
                    {
                        toreplace += storetemplate.Replace("[storeidx]", paras.Length.ToString()).Replace("[argidx]", i.ToString());
                    }
                }

                funccode = funccode.Replace("[storeref]", toreplace);
            }


            if (ismakedelegate)
            {
                //typeof(AutoGenCodeLib.Testobj).GetMethod("TestType");

                string types = "Type.EmptyTypes";

                if (paras.Length > 0)
                {
                    types = "new Type[] {";

                    for (int i = 0; i < paras.Length; i++)
                    {
                        types += "typeof(" + GetTypeFullName(paras[i].ParameterType) + ")";
                        if (i < paras.Length - 1)
                        {
                            types += ",";
                        }
                    }

                    types += "}";
                }


                string findmethod = string.Empty;
                findmethod += "typeof(" + GetTypeFullName(methodAtType) + ")";
                findmethod += ".GetMethod(\"" + method.Name + "\"," + types + ");";


                funccode = funccode.Replace("[createmethod]", findmethod);
            }



            return(funccode);
        }