Exemplo n.º 1
0
        string MatchEvaluator(Match m)
        {
            switch (m.Value.Substring(1, m.Value.Length - 2))
            {
            case "Tracking":
                return(TrackingType == null ? "null" : $"new {TrackingType.GetFriendlyName()}()");

            case "async":
                return(IsAsync ? "async" : "");

            case "ResultType":
                return(ReturnType.GetFriendlyName());

            case "InterfaceName":
                return(InterfaceType.GetFriendlyName());

            case "MethodName":
                return(MethodName);

            case "MethodArgs":
                return(string.Join(", ", Params.Select(GetMethodArgumentDefinition)));

            case "HttpMethod":
                return(HttpMethod.ToString());

            case "Template":
                return(Template.Replace("\n", "%0A")
                       .Replace("\r", "%0D")
                       .Replace("\"", "%22"));

            case "Params":
                return(string.Join("\r\n                ", Params.Select(GetSetParamDefinition)));

            case "return":
                return(ReturnType != null && ReturnType != typeof(void) && ReturnType != typeof(Task) ? "return" : "");

            case "await":
                return(IsAsync ? "await" : "");

            case "Invoker":
                var type   = ReturnType;
                var @async = "";
                if (IsAsync)
                {
                    if (type == typeof(Task))
                    {
                        type = null;
                    }
                    else
                    {
                        type = type.GetGenericArguments()[0];
                    }
                    @async = "Async";
                }
                if (type == typeof(string))
                {
                    return("GetString" + @async);
                }
                else if (type == typeof(byte[]))
                {
                    return("GetBytes" + @async);
                }
                else if (type == null || type == typeof(void) || type == typeof(IHttpResponse))
                {
                    return("Send" + @async);
                }
                return($"GetObject{@async}<{type.GetFriendlyName()}>");

            case "RemoveParams":
                return(string.Join(";", Params.Select(GetRemoveParamDefinition)));

            case "ContentType":
                return(ContentType == null ? "null" : $"\"{ContentType}\"");

            default:
                return("");
            }
        }