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); }
private static string GetAttribute(AttributeMetadataProxy attributemetadata, Settings settings) { var name = attributemetadata.Metadata.IsPrimaryId == true ? "PrimaryKey" : attributemetadata.Metadata.IsPrimaryName == true ? "PrimaryName" : attributemetadata.GetNameTechnical(settings); name = settings.commonsettings.AttributePrefix + name + settings.commonsettings.AttributeSuffix; var description = attributemetadata.Description?.Replace("\n", "\n/// "); var summary = settings.XmlProperties ? attributemetadata.AttributeProperties : settings.XmlDescription ? description : string.Empty; summary = summary?.Replace("\n", "\n/// "); var remarks = settings.XmlProperties && settings.XmlDescription ? description : string.Empty; var attribute = new StringBuilder(); if (!string.IsNullOrEmpty(summary)) { attribute.AppendLine($"/// <summary>{summary}</summary>"); } if (!string.IsNullOrEmpty(remarks)) { attribute.AppendLine($"/// <remarks>{remarks}</remarks>"); } attribute.AppendLine(Template.Attribute .Replace("{attribute}", name) .Replace("{logicalname}", attributemetadata.LogicalName) .Replace("'", "\"")); return(attribute.ToString()); }
private static string GetAttribute(AttributeMetadataProxy attributemetadata, Settings settings) { var template = settings.commonsettings.Template; var name = attributemetadata.GetNameTechnical(settings); if (attributemetadata == attributemetadata.Entity.PrimaryKey) { name = template.PrimaryKeyName.Replace("{attribute}", name); } if (attributemetadata == attributemetadata.Entity.PrimaryName) { name = template.PrimaryAttributeName.Replace("{attribute}", name); } name = settings.commonsettings.AttributePrefix + name + settings.commonsettings.AttributeSuffix; var entityname = attributemetadata.Entity.GetNameTechnical(settings.ConstantName, settings); if (name.Equals(entityname)) { name += "_"; } name = attributemetadata.Metadata.IsCustomAttribute.Value ? template.CustomAttribute.ReplaceIfNotEmpty("{attribute}", name) : template.StandardAttribute.ReplaceIfNotEmpty("{attribute}", name); switch (attributemetadata.Metadata.RequiredLevel.Value) { case AttributeRequiredLevel.ApplicationRequired: case AttributeRequiredLevel.SystemRequired: name = template.RequiredLevelRequired.ReplaceIfNotEmpty("{attribute}", name); break; case AttributeRequiredLevel.Recommended: name = template.RequiredLevelRecommended.ReplaceIfNotEmpty("{attribute}", name); break; case AttributeRequiredLevel.None: name = template.RequiredLevelNone.ReplaceIfNotEmpty("{attribute}", name); break; } if (settings.ValidateIdentifiers) { name = UnicodeCharacterUtilities.MakeValidIdentifier(name, true); } var description = attributemetadata.Description?.Replace("\n", "\n/// "); var summary = settings.XmlProperties ? attributemetadata.AttributeProperties : settings.XmlDescription ? description : string.Empty; var remarks = settings.XmlProperties && settings.XmlDescription ? description : string.Empty; if (!string.IsNullOrEmpty(summary)) { summary = template.Summary.Replace("{summary}", summary.Replace("\n", "\n/// ")); } if (!string.IsNullOrEmpty(remarks)) { remarks = template.Remarks.Replace("{remarks}", remarks); } var attribute = template.Attribute .Replace("{attribute}", name) .Replace("{logicalname}", attributemetadata.LogicalName) .Replace("{type}", attributemetadata.Type.ToString()) .Replace("{summary}", summary) .Replace("{remarks}", remarks) .Replace("'", "\""); return(attribute); }