Beispiel #1
0
        private static string GetMapping(ParameterMapping mapping, bool filterRequired = false)
        {
            string inputPath = mapping.InputParameter.Name;

            if (mapping.InputParameterProperty != null)
            {
                inputPath += "." + CodeNamer.CamelCase(mapping.InputParameterProperty) + "()";
            }
            if (filterRequired && !mapping.InputParameter.IsRequired)
            {
                inputPath = "null";
            }

            string outputPath = "";

            if (mapping.OutputParameterProperty != null)
            {
                outputPath += ".with" + CodeNamer.PascalCase(mapping.OutputParameterProperty);
                return(string.Format(CultureInfo.InvariantCulture, "{0}({1})", outputPath, inputPath));
            }
            else
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0} = {1}", outputPath, inputPath));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Flattens the Resource Properties.
        /// </summary>
        /// <param name="serviceClient"></param>
        public static void FlattenResourceProperties(ServiceClient serviceClient)
        {
            if (serviceClient == null)
            {
                throw new ArgumentNullException("serviceClient");
            }

            HashSet <string> typesToDelete = new HashSet <string>();

            foreach (var compositeType in serviceClient.ModelTypes.ToArray())
            {
                if (IsAzureResource(compositeType))
                {
                    CheckAzureResourceProperties(compositeType);

                    // First find "properties" property
                    var propertiesProperty = compositeType.ComposedProperties.FirstOrDefault(
                        p => p.Name.Equals(ResourceProperties, StringComparison.OrdinalIgnoreCase));

                    // Sub resource does not need to have properties
                    if (propertiesProperty != null)
                    {
                        var propertiesModel = propertiesProperty.Type as CompositeType;
                        // Recursively parsing the "properties" object hierarchy
                        while (propertiesModel != null)
                        {
                            foreach (Property originalProperty in propertiesModel.Properties)
                            {
                                var pp = (Property)originalProperty.Clone();
                                if (
                                    ResourcePropertyNames.Any(
                                        rp => rp.Equals(pp.Name, StringComparison.OrdinalIgnoreCase)))
                                {
                                    pp.Name = compositeType.Name + CodeNamer.PascalCase(pp.Name);
                                }
                                pp.SerializedName = "properties." + pp.SerializedName;
                                compositeType.Properties.Add(pp);
                            }

                            compositeType.Properties.Remove(propertiesProperty);
                            if (!typesToDelete.Contains(propertiesModel.Name))
                            {
                                typesToDelete.Add(propertiesModel.Name);
                            }
                            propertiesModel = propertiesModel.BaseModelType;
                        }
                    }
                }
            }

            AzureExtensions.RemoveUnreferencedTypes(serviceClient, typesToDelete);
        }
Beispiel #3
0
        private static string GetMapping(ParameterMapping mapping)
        {
            string inputPath = mapping.InputParameter.Name;

            if (mapping.InputParameterProperty != null)
            {
                inputPath += ".get" + CodeNamer.PascalCase(mapping.InputParameterProperty) + "()";
            }

            string outputPath = "";

            if (mapping.OutputParameterProperty != null)
            {
                outputPath += ".set" + CodeNamer.PascalCase(mapping.OutputParameterProperty);
                return(string.Format(CultureInfo.InvariantCulture, "{0}({1})", outputPath, inputPath));
            }
            else
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0} = {1}", outputPath, inputPath));
            }
        }
Beispiel #4
0
        public void PascalCase(string expected, string value)
        {
            var result = CodeNamer.PascalCase(value);

            Assert.Equal(expected, result);
        }
Beispiel #5
0
 /// <summary>
 /// Converts the specified string to a pascal cased string.
 /// </summary>
 /// <param name="value">The string to convert.</param>
 /// <returns>The pascal case string.</returns>
 public static string ToPascalCase(this string value)
 {
     return(CodeNamer.PascalCase(value));
 }