public static CompositeTypeTS CompositeType(string name = null, IEnumerable <PropertyTS> properties = null) { CompositeTypeTS compositeType = new CompositeTypeTS(name); if (properties != null) { foreach (PropertyTS property in properties) { compositeType.Add(property); } } return(compositeType); }
public static CompositeTypeTS CompositeType(string name = null, IEnumerable <PropertyTS> properties = null, string xmlPrefix = null, string xmlName = null) { CompositeTypeTS compositeType = new CompositeTypeTS(name); if (!string.IsNullOrEmpty(xmlPrefix)) { compositeType.XmlProperties = new XmlProperties { Name = xmlName, Prefix = xmlPrefix, }; } if (properties != null) { foreach (PropertyTS property in properties) { compositeType.Add(property); } } return(compositeType); }
public override void CreateModelTypeForOptionalClientProperties(CodeModelTS cm) { List <string> predefinedOptionalProperties = new List <string>() { "requestOptions", "filters", "noRetryPolicy", "apiVersion", "acceptLanguage", "longRunningOperationRetryTimeout", "generateClientRequestId", "rpRegistrationRetryTimeout" }; var optionalProperitesOnClient = cm.Properties.Where( p => (!p.IsRequired || p.IsRequired && !string.IsNullOrEmpty(p.DefaultValue)) && !p.IsConstant && !predefinedOptionalProperties.Contains(p.Name)); if (optionalProperitesOnClient.Count() > 0 || !cm.IsCustomBaseUri) { string modelTypeName = cm.Name + "Options"; var modelType = new CompositeTypeTS(modelTypeName); modelType.BaseModelType = New <CompositeType>(new { Name = "AzureServiceClientOptions", SerializedName = "AzureServiceClientOptions" }); // We could end up having a property that is required but has a default value based on the above condition. If so then make it optional. optionalProperitesOnClient.Where(p => p.IsRequired && !string.IsNullOrEmpty(p.DefaultValue)).ForEach(prop => prop.IsRequired = false); modelType.AddRange(optionalProperitesOnClient); if (!cm.IsCustomBaseUri) { var prop = New <PropertyTS>(); prop.Name = "baseUri"; prop.ModelType = new PrimaryTypeTS(KnownPrimaryType.String); modelType.Add(prop); } var modelTypeFound = cm.ModelTypes.FirstOrDefault(m => m.Name.EqualsIgnoreCase(modelTypeName)); if (modelTypeFound != null) { cm.Remove(modelTypeFound); } cm.Add(modelType); cm.OptionalParameterTypeForClientConstructor = "Models." + modelTypeName; } }