Beispiel #1
0
 private string GenerateServiceInterfaceMethod(MethodInfo methodInfo, Type returnType, ParamRec[] before)
 {
     string type = CodeGeneratorHelper.TypeToString(returnType ?? methodInfo.ReturnType);
     string name = methodInfo.Name;
     string pars = CodeGeneratorHelper.MakeMethodArgsDefinitionCode(methodInfo, before);
     string res = "        {0} {1}({2});".FormatWith(type, name, pars);
     return res;
 }
Beispiel #2
0
        private string GenerateServiceProxyMethod(MethodInfo methodInfo, Type returnType, ParamRec[] before)
        {
            TemplateResolver rsv = new TemplateResolver(CodeGeneratorHelper.GetTemplate(@"TauCode.Wagen.Client.Resources.ServiceProxyMethod.txt"));

            Type actualReturnType = returnType ?? methodInfo.ReturnType;
            string type = CodeGeneratorHelper.TypeToString(actualReturnType);
            string name = methodInfo.Name;

            rsv.Map("returnType", type);

            rsv.Map("methodName", name);
            rsv.Map("argsDefinition", CodeGeneratorHelper.MakeMethodArgsDefinitionCode(
                methodInfo,
                before));

            string[] beforeArgValues = _isAccountHandle ? new[] { "sessionId" } : null;

            rsv.Map("args", CodeGeneratorHelper.MakeMethodArgsCode(methodInfo, beforeArgValues, true));

            // return
            string resTypeCasting;
            string ret;

            if (actualReturnType == typeof(void))
            {
                resTypeCasting = string.Empty;
                ret = "// no return from void";
            }
            else
            {
                resTypeCasting = "{0} res = ({0})".FormatWith(type);
                ret = "return res;";
            }

            rsv.Map("result-type-casting", resTypeCasting);
            rsv.Map("return", ret);

            return rsv.Resolve();
        }
Beispiel #3
0
        internal static string MakeMethodArgsDefinitionCode(MethodInfo methodInfo, ParamRec[] before)
        {
            List<ParamRec> pars = new List<ParamRec>();
            if (before != null)
            {
                pars.AddRange(before);
            }

            pars.AddRange(methodInfo.GetParameters().Select(pi => new ParamRec(pi.ParameterType, pi.Name)));

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < pars.Count; i++)
            {
                var pi = pars[i];
                sb.AppendFormat("{0} {1}", CodeGeneratorHelper.TypeToString(pi.Type), pi.Name);

                if (i < pars.Count - 1)
                {
                    sb.Append(", ");
                }
            }

            string res = sb.ToString();

            return res;
        }