Ejemplo n.º 1
0
        /// <summary>
        /// Return formatted value string for the parameter.
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static string ValueForMap(this Parameter parameter)
        {
            if (parameter.SerializedName.IsApiVersion())
            {
                return("client." + ApiVersionName);
            }
            var value = parameter.IsClientProperty()
                ? "client." + GoCodeNamer.PascalCase(parameter.Name)
                : parameter.Name;

            var format = parameter.IsRequired || parameter.Type.CanBeEmpty()
                                          ? "{0}"
                                          : "*{0}";

            var s = parameter.CollectionFormat != CollectionFormat.None
                                  ? $"{format},\"{parameter.CollectionFormat.GetSeparator()}\""
                                  : $"{format}";

            return(string.Format(
                       parameter.RequiresUrlEncoding()
                    ? $"autorest.Encode(\"{parameter.Location.ToString().ToLower()}\",{s})"
                    : $"{s}",
                       value));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add NextLink attribute for pageable extension for the method.
        /// </summary>
        /// <param name="method"></param>
        /// <returns></returns>
        public static string NextLink(this Method method)
        {
            var nextLink = "";

            // Note:
            // -- The CSharp generator applies a default link name if the extension is present but the link name is not.
            //    Yet, the MSDN for methods whose nextLink is missing are not paged methods. It appears the CSharp code is
            //    outdated vis a vis the specification.
            // TODO (gosdk): Ensure obtaining the nextLink is correct.
            if (method.Extensions.ContainsKey(AzureExtensions.PageableExtension))
            {
                var pageableExtension = method.Extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer;
                if (pageableExtension != null)
                {
                    var nextLinkName = (string)pageableExtension["nextLinkName"];
                    if (!string.IsNullOrEmpty(nextLinkName))
                    {
                        nextLink = GoCodeNamer.PascalCase(nextLinkName);
                    }
                }
            }

            return(nextLink);
        }