private static string GetOptionSet(AttributeMetadataProxy attributemetadata, Settings settings) { var name = settings.commonsettings.OptionSetEnumPrefix + attributemetadata.GetNameTechnical(settings) + settings.commonsettings.OptionSetEnumSuffix; var optionset = Template.OptionSet.Replace("{name}", name); var options = new List <string>(); var optionsetmetadata = attributemetadata.Metadata as EnumAttributeMetadata; if (optionsetmetadata != null && optionsetmetadata.OptionSet != null) { foreach (var optionmetadata in optionsetmetadata.OptionSet.Options) { var label = MetadataProxy.StringToCSharpIdentifier(optionmetadata.Label.UserLocalizedLabel.Label); if (settings.ConstantCamelCased) { label = label.CamelCaseIt(settings); } if (string.IsNullOrEmpty(label) || int.TryParse(label[0].ToString(), out int tmp)) { label = "_" + label; } var option = Template.OptionSetValue .Replace("{name}", label) .Replace("{value}", optionmetadata.Value.ToString()); options.Add(option); } } optionset = optionset.Replace("{values}", string.Join(",\r\n", options)); return(optionset); }
private static string GetOptionSet(AttributeMetadataProxy attributemetadata, Settings settings) { var name = settings.commonsettings.OptionSetEnumPrefix + attributemetadata.GetNameTechnical(settings) + settings.commonsettings.OptionSetEnumSuffix; var optionset = settings.commonsettings.Template.OptionSet.Replace("{name}", name); var options = new List <string>(); if (attributemetadata.Metadata is EnumAttributeMetadata optionsetmetadata && optionsetmetadata.OptionSet != null) { foreach (var optionmetadata in optionsetmetadata.OptionSet.Options) { var label = MetadataProxy.StringToCSharpIdentifier(optionmetadata.Label.UserLocalizedLabel.Label); if (settings.ConstantCamelCased) { label = label.CamelCaseIt(settings); } if (string.IsNullOrEmpty(label) || !UnicodeCharacterUtilities.IsIdentifierStartCharacter(label[0]) || !label.IsValidIdentifier()) { label = "_" + label; } var option = settings.commonsettings.Template.OptionSetValue .Replace("{name}", label) .Replace("{value}", optionmetadata.Value.ToString()); options.Add(option); } } DeduplicateIdentifiers(ref options); optionset = optionset.Replace("{values}", string.Join(",\r\n", options)); return(optionset); }