Exemplo n.º 1
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));
 }
Exemplo n.º 2
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);
        }