Ejemplo n.º 1
0
        private static string GetContextMethod(JsonUrlGeneratedClass c)
        {
            var hs = c.OriginalInput
                     .Headers
                     .Select(h => String.Format("Tuple.Create({0},{1})", ToLiteral(h.Name), ToLiteral(h.Value)));

            var hsParam = String.Format("new List<Tuple<string,string>> {{ {0} }}", String.Join(", ", hs));

            if (c.OriginalInput.GenerateAsMethod)
            {
                var ns   = c.Namespace;
                var name = GetNameForMethod(c);
                var cls  = c.ClassName;

                var url = c.Url;
                var ps  = c.OriginalInput.GetUrlQueryStringParameters();

                var args      = String.Join(", ", ps.Select(p => String.Format("string {0} = {1}", p.Item1, ToLiteral(p.Item2))));
                var prototype = String.Format("public IEnumerable<{0}.{1}> {2}({3})", ns, cls, name, args);

                var methodBody =
                    String.Format("var _____uri = new UriBuilder(@\"{0}\");\r\n", url) +
                    String.Format("var _____q = HttpUtility.ParseQueryString(_____uri.Query);\r\n\r\n") +
                    String.Join(Environment.NewLine, ps.Select(q => String.Format("_____q[\"{0}\"] = {0};", q.Item1))) + "\r\n\r\n" +
                    String.Format("_____uri.Query = _____q.ToString();\r\n\r\n") +

                    String.Format("return GetUrlParameterlessInput<{0}.{1}>(_____uri.ToString(), {2});", ns, cls, hsParam);

                return(String.Format("{0}\r\n{{\r\n{1}\r\n}}", prototype, methodBody));
            }
            else
            {
                return(String.Format(
                           "public IEnumerable<{0}.{1}> {2}s {{ get {{ return GetUrlParameterlessInput<{0}.{1}>(@\"{3}\", {4}); }} }}",
                           c.Namespace, c.ClassName, c.ClassName, c.Url, hsParam));
            }
        }
Ejemplo n.º 2
0
 private static string GetNameForMethod(JsonUrlGeneratedClass c)
 {
     return(String.Format("Get{0}", c.ClassName.SanitiseClassName()));
 }
 private static string GetNameForMethod(JsonUrlGeneratedClass c)
 {
     return String.Format("Get{0}", c.ClassName.SanitiseClassName());
 }
        private static string GetContextMethod(JsonUrlGeneratedClass c)
        {
            var hs = c.OriginalInput
                .Headers
                .Select(h => String.Format("Tuple.Create({0},{1})", ToLiteral(h.Name), ToLiteral(h.Value)));

            var hsParam = String.Format("new List<Tuple<string,string>> {{ {0} }}", String.Join(", ", hs));

            if (c.OriginalInput.GenerateAsMethod)
            {
                var ns = c.Namespace;
                var name = GetNameForMethod(c);
                var cls = c.ClassName;

                var url = c.Url;
                var ps = c.OriginalInput.GetUrlQueryStringParameters();

                var args = String.Join(", ", ps.Select(p => String.Format("string {0} = {1}", p.Item1, ToLiteral(p.Item2))));
                var prototype = String.Format("public IEnumerable<{0}.{1}> {2}({3})", ns, cls, name, args);

                var methodBody =
                    String.Format("var _____uri = new UriBuilder(@\"{0}\");\r\n", url) +
                    String.Format("var _____q = HttpUtility.ParseQueryString(_____uri.Query);\r\n\r\n") +
                    String.Join(Environment.NewLine, ps.Select(q => String.Format("_____q[\"{0}\"] = {0};", q.Item1))) + "\r\n\r\n" +
                    String.Format("_____uri.Query = _____q.ToString();\r\n\r\n") +

                    String.Format("return GetUrlParameterlessInput<{0}.{1}>(_____uri.ToString(), {2});", ns, cls, hsParam);

                return String.Format("{0}\r\n{{\r\n{1}\r\n}}", prototype, methodBody);
            }
            else
                return String.Format(
                    "public IEnumerable<{0}.{1}> {2}s {{ get {{ return GetUrlParameterlessInput<{0}.{1}>(@\"{3}\", {4}); }} }}",
                    c.Namespace, c.ClassName, c.ClassName, c.Url, hsParam);
        }