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