diff --git a/XmlSchemaClassGenerator/INamingProvider.cs b/XmlSchemaClassGenerator/INamingProvider.cs
index 550379e8..d04d6dad 100644
--- a/XmlSchemaClassGenerator/INamingProvider.cs
+++ b/XmlSchemaClassGenerator/INamingProvider.cs
@@ -1,6 +1,7 @@
namespace XmlSchemaClassGenerator
{
using System.Xml;
+ using System.Xml.Schema;
public interface INamingProvider
{
@@ -9,39 +10,90 @@ public interface INamingProvider
///
/// Name of the typeModel
/// Attribute name
+ /// Original XSD attribute
/// Name of the property
- string PropertyNameFromAttribute(string typeModelName, string attributeName);
+ string PropertyNameFromAttribute(string typeModelName, string attributeName, XmlSchemaAttribute attribute);
///
/// Creates a name for a property from an element name
///
/// Name of the typeModel
/// Element name
+ /// Original XSD element
/// Name of the property
- string PropertyNameFromElement(string typeModelName, string elementName);
+ string PropertyNameFromElement(string typeModelName, string elementName, XmlSchemaElement element);
///
/// Creates a name for an enum member based on a value
///
/// Name of the enum
/// Value name
+ /// Original XSD enumeration facet
/// Name of the enum member
- string EnumMemberNameFromValue(string enumName, string value);
+ string EnumMemberNameFromValue(string enumName, string value, XmlSchemaEnumerationFacet xmlFacet);
- string ComplexTypeNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used when a ComplexType is found in the XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD ComplexType
+ /// A string with a valid C# identifier name.
+ string ComplexTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaComplexType complexType);
- string AttributeGroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used when a AttributeGroup is found in the XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD AttributeGroup
+ /// A string with a valid C# identifier name.
+ string AttributeGroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaAttributeGroup attributeGroup);
- string GroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used when a GroupType is found in the XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD group
+ /// A string with a valid C# identifier name.
+ string GroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaGroup group);
- string SimpleTypeNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used when a SimpleType is found in the XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD SimpleType
+ /// A string with a valid C# identifier name.
+ string SimpleTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaSimpleType simpleType);
- string RootClassNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used for the root class.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD element
+ /// A string with a valid C# identifier name.
+ string RootClassNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaElement xmlElement);
- string EnumTypeNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used when an enum type is found in the XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD SimpleType
+ /// A string with a valid C# identifier name.
+ string EnumTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaSimpleType xmlSimpleType);
- string AttributeNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name to be used when an attribute is found in the XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD attribute
+ /// A string with a valid C# identifier name.
+ string AttributeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaAttribute xmlAttribute);
- string ElementNameFromQualifiedName(XmlQualifiedName qualifiedName);
+ ///
+ /// Define the name of the C# class property from the element name in XSD.
+ ///
+ /// The name as defined in the XSD if present.
+ /// Original XSD element
+ /// A string with a valid C# identifier name.
+ string ElementNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaElement xmlElement);
}
}
\ No newline at end of file
diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs
index c9ec1fce..8a4db504 100644
--- a/XmlSchemaClassGenerator/ModelBuilder.cs
+++ b/XmlSchemaClassGenerator/ModelBuilder.cs
@@ -265,7 +265,7 @@ private void CreateElements(IEnumerable elements)
derivedClassModel = new ClassModel(_configuration)
{
- Name = _configuration.NamingProvider.RootClassNameFromQualifiedName(rootElement.QualifiedName),
+ Name = _configuration.NamingProvider.RootClassNameFromQualifiedName(rootElement.QualifiedName, rootElement),
Namespace = CreateNamespaceModel(elementSource, rootElement.QualifiedName)
};
@@ -291,7 +291,7 @@ private void CreateElements(IEnumerable elements)
var originalClassModel = new ClassModel(_configuration)
{
- Name = _configuration.NamingProvider.RootClassNameFromQualifiedName(type.RootElementName),
+ Name = _configuration.NamingProvider.RootClassNameFromQualifiedName(type.RootElementName, rootElement),
Namespace = classModel.Namespace
};
@@ -404,7 +404,7 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaAnnotated type, XmlQualif
private TypeModel CreateTypeModel(Uri source, XmlSchemaGroup group, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List docs)
{
- var name = "I" + _configuration.NamingProvider.GroupTypeNameFromQualifiedName(qualifiedName);
+ var name = "I" + _configuration.NamingProvider.GroupTypeNameFromQualifiedName(qualifiedName, group);
if (namespaceModel != null) { name = namespaceModel.GetUniqueTypeName(name); }
var interfaceModel = new InterfaceModel(_configuration)
@@ -438,7 +438,7 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaGroup group, NamespaceMod
private TypeModel CreateTypeModel(Uri source, XmlSchemaAttributeGroup attributeGroup, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List docs)
{
- var name = "I" + _configuration.NamingProvider.AttributeGroupTypeNameFromQualifiedName(qualifiedName);
+ var name = "I" + _configuration.NamingProvider.AttributeGroupTypeNameFromQualifiedName(qualifiedName, attributeGroup);
if (namespaceModel != null) { name = namespaceModel.GetUniqueTypeName(name); }
var interfaceModel = new InterfaceModel(_configuration)
@@ -470,7 +470,7 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaAttributeGroup attributeG
private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List docs)
{
- var name = _configuration.NamingProvider.ComplexTypeNameFromQualifiedName(qualifiedName);
+ var name = _configuration.NamingProvider.ComplexTypeNameFromQualifiedName(qualifiedName, complexType);
if (namespaceModel != null)
{
name = namespaceModel.GetUniqueTypeName(name);
@@ -649,7 +649,7 @@ private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType, NamespaceModel
if (isEnum)
{
// we got an enum
- var name = _configuration.NamingProvider.EnumTypeNameFromQualifiedName(qualifiedName);
+ var name = _configuration.NamingProvider.EnumTypeNameFromQualifiedName(qualifiedName, simpleType);
if (namespaceModel != null) { name = namespaceModel.GetUniqueTypeName(name); }
var enumModel = new EnumModel(_configuration)
@@ -667,7 +667,7 @@ private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType, NamespaceModel
{
var value = new EnumValueModel
{
- Name = _configuration.NamingProvider.EnumMemberNameFromValue(enumModel.Name, facet.Value),
+ Name = _configuration.NamingProvider.EnumMemberNameFromValue(enumModel.Name, facet.Value, facet),
Value = facet.Value
};
@@ -699,7 +699,7 @@ private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType, NamespaceModel
restrictions = GetRestrictions(facets, simpleType).Where(r => r != null).Sanitize().ToList();
}
- var simpleModelName = _configuration.NamingProvider.SimpleTypeNameFromQualifiedName(qualifiedName);
+ var simpleModelName = _configuration.NamingProvider.SimpleTypeNameFromQualifiedName(qualifiedName, simpleType);
if (namespaceModel != null) { simpleModelName = namespaceModel.GetUniqueTypeName(simpleModelName); }
var simpleModel = new SimpleModel(_configuration)
@@ -756,7 +756,7 @@ private IEnumerable CreatePropertiesForAttributes(Uri source, Typ
if (attribute.Use != XmlSchemaUse.Prohibited)
{
var attributeQualifiedName = attribute.AttributeSchemaType.QualifiedName;
- var attributeName = _configuration.NamingProvider.AttributeNameFromQualifiedName(attribute.QualifiedName);
+ var attributeName = _configuration.NamingProvider.AttributeNameFromQualifiedName(attribute.QualifiedName, attribute);
if (attribute.Parent is XmlSchemaAttributeGroup attributeGroup
&& attributeGroup.QualifiedName != typeModel.XmlSchemaName
@@ -776,7 +776,7 @@ private IEnumerable CreatePropertiesForAttributes(Uri source, Typ
if (attributeQualifiedName.IsEmpty || string.IsNullOrEmpty(attributeQualifiedName.Namespace))
{
// inner type, have to generate a type name
- var typeName = _configuration.NamingProvider.PropertyNameFromAttribute(typeModel.Name, attribute.QualifiedName.Name);
+ var typeName = _configuration.NamingProvider.PropertyNameFromAttribute(typeModel.Name, attribute.QualifiedName.Name, attribute);
attributeQualifiedName = new XmlQualifiedName(typeName, typeModel.XmlSchemaName.Namespace);
// try to avoid name clashes
if (NameExists(attributeQualifiedName))
@@ -864,7 +864,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM
{
// inner type, have to generate a type name
var typeModelName = xmlParticle is XmlSchemaGroupRef groupRef ? groupRef.RefName : typeModel.XmlSchemaName;
- var typeName = _configuration.NamingProvider.PropertyNameFromElement(typeModelName.Name, element.QualifiedName.Name);
+ var typeName = _configuration.NamingProvider.PropertyNameFromElement(typeModelName.Name, element.QualifiedName.Name, element);
elementQualifiedName = new XmlQualifiedName(typeName, typeModel.XmlSchemaName.Namespace);
// try to avoid name clashes
if (NameExists(elementQualifiedName))
@@ -877,7 +877,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM
}
var effectiveElement = substitute?.Element ?? element;
- var propertyName = _configuration.NamingProvider.ElementNameFromQualifiedName(effectiveElement.QualifiedName);
+ var propertyName = _configuration.NamingProvider.ElementNameFromQualifiedName(effectiveElement.QualifiedName, effectiveElement);
var originalPropertyName = propertyName;
if (propertyName == typeModel.Name)
{
diff --git a/XmlSchemaClassGenerator/NamingProvider.cs b/XmlSchemaClassGenerator/NamingProvider.cs
index c6efe827..754a0d00 100644
--- a/XmlSchemaClassGenerator/NamingProvider.cs
+++ b/XmlSchemaClassGenerator/NamingProvider.cs
@@ -1,6 +1,7 @@
namespace XmlSchemaClassGenerator
{
using System.Xml;
+ using System.Xml.Schema;
///
/// Provides options to customize member names
@@ -24,10 +25,11 @@ public NamingProvider(NamingScheme namingScheme)
///
/// Name of the typeModel
/// Attribute name
+ /// Original XSD attribute
/// Name of the property
- public virtual string PropertyNameFromAttribute(string typeModelName, string attributeName)
+ public virtual string PropertyNameFromAttribute(string typeModelName, string attributeName, XmlSchemaAttribute attribute)
{
- return PropertyNameFromElement(typeModelName, attributeName);
+ return typeModelName.ToTitleCase(_namingScheme) + attributeName.ToTitleCase(_namingScheme);
}
///
@@ -35,8 +37,9 @@ public virtual string PropertyNameFromAttribute(string typeModelName, string att
///
/// Name of the typeModel
/// Element name
+ /// Original XSD element
/// Name of the property
- public virtual string PropertyNameFromElement(string typeModelName, string elementName)
+ public virtual string PropertyNameFromElement(string typeModelName, string elementName, XmlSchemaElement element)
{
return typeModelName.ToTitleCase(_namingScheme) + elementName.ToTitleCase(_namingScheme);
}
@@ -46,8 +49,9 @@ public virtual string PropertyNameFromElement(string typeModelName, string eleme
///
/// Name of the enum
/// Value name
+ /// Original XSD enumeration facet
/// Name of the enum member
- public virtual string EnumMemberNameFromValue(string enumName, string value)
+ public virtual string EnumMemberNameFromValue(string enumName, string value, XmlSchemaEnumerationFacet xmlFacet)
{
return value.ToTitleCase(_namingScheme).ToNormalizedEnumName();
}
@@ -56,8 +60,9 @@ public virtual string EnumMemberNameFromValue(string enumName, string value)
/// Define the name to be used when a ComplexType is found in the XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD ComplexType
/// A string with a valid C# identifier name.
- public virtual string ComplexTypeNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string ComplexTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaComplexType complexType)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -66,8 +71,9 @@ public virtual string ComplexTypeNameFromQualifiedName(XmlQualifiedName qualifie
/// Define the name to be used when a AttributeGroup is found in the XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD AttributeGroup
/// A string with a valid C# identifier name.
- public virtual string AttributeGroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string AttributeGroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaAttributeGroup attributeGroup)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -76,8 +82,9 @@ public virtual string AttributeGroupTypeNameFromQualifiedName(XmlQualifiedName q
/// Define the name to be used when a GroupType is found in the XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD group
/// A string with a valid C# identifier name.
- public virtual string GroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string GroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaGroup group)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -86,8 +93,9 @@ public virtual string GroupTypeNameFromQualifiedName(XmlQualifiedName qualifiedN
/// Define the name to be used when a SimpleType is found in the XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD SimpleType
/// A string with a valid C# identifier name.
- public virtual string SimpleTypeNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string SimpleTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaSimpleType simpleType)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -96,8 +104,9 @@ public virtual string SimpleTypeNameFromQualifiedName(XmlQualifiedName qualified
/// Define the name to be used for the root class.
///
/// The name as defined in the XSD if present.
+ /// Original XSD element
/// A string with a valid C# identifier name.
- public virtual string RootClassNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string RootClassNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaElement xmlElement)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -106,8 +115,9 @@ public virtual string RootClassNameFromQualifiedName(XmlQualifiedName qualifiedN
/// Define the name to be used when an enum type is found in the XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD SimpleType
/// A string with a valid C# identifier name.
- public virtual string EnumTypeNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string EnumTypeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaSimpleType xmlSimpleType)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -116,8 +126,9 @@ public virtual string EnumTypeNameFromQualifiedName(XmlQualifiedName qualifiedNa
/// Define the name to be used when an attribute is found in the XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD attribute
/// A string with a valid C# identifier name.
- public virtual string AttributeNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string AttributeNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaAttribute xmlAttribute)
{
return QualifiedNameToTitleCase(qualifiedName);
}
@@ -126,8 +137,9 @@ public virtual string AttributeNameFromQualifiedName(XmlQualifiedName qualifiedN
/// Define the name of the C# class property from the element name in XSD.
///
/// The name as defined in the XSD if present.
+ /// Original XSD element
/// A string with a valid C# identifier name.
- public virtual string ElementNameFromQualifiedName(XmlQualifiedName qualifiedName)
+ public virtual string ElementNameFromQualifiedName(XmlQualifiedName qualifiedName, XmlSchemaElement xmlElement)
{
return QualifiedNameToTitleCase(qualifiedName);
}