示例#1
0
        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);
        }
示例#2
0
 internal static string StringToCSharpIdentifier(string name)
 {
     name = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(name))
            .Replace(" ", "")
            .Replace("(", "")
            .Replace(")", "")
            .Replace("<", "")
            .Replace(">", "")
            .Replace(".", "")
            .Replace(",", "")
            .Replace(";", "")
            .Replace(":", "")
            .Replace("'", "")
            .Replace("*", "")
            .Replace("&", "")
            .Replace("%", "")
            .Replace("-", "_")
            .Replace("+", "_")
            .Replace("/", "_")
            .Replace("\\", "_")
            .Replace("[", "_")
            .Replace("]", "_");
     return(UnicodeCharacterUtilities.MakeValidIdentifier(name, false));
 }
示例#3
0
        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);
        }