From 9e372e223dad07902437401c3f9518cc7214aac3 Mon Sep 17 00:00:00 2001 From: Henrik Fuchs Date: Thu, 11 May 2017 09:34:17 +0200 Subject: [PATCH 1/3] Order for AnyAttribute, optional DebuggerStepThroughAttribute (new command line option) --- XmlSchemaClassGenerator.Console/Program.cs | 8 +++++-- XmlSchemaClassGenerator/Generator.cs | 22 ++++++++++++++++++- .../GeneratorConfiguration.cs | 4 ++++ XmlSchemaClassGenerator/TypeModel.cs | 11 +++++++--- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/XmlSchemaClassGenerator.Console/Program.cs b/XmlSchemaClassGenerator.Console/Program.cs index d7ab27b1..4ef476fc 100644 --- a/XmlSchemaClassGenerator.Console/Program.cs +++ b/XmlSchemaClassGenerator.Console/Program.cs @@ -33,6 +33,7 @@ static void Main(string[] args) Type collectionImplementationType = null; var codeTypeReferenceOptions = default(CodeTypeReferenceOptions); string textValuePropertyName = "Value"; + var generateDebuggerStepThroughAttribute = true; var options = new OptionSet { { "h|help", "show this message and exit", v => showHelp = v != null }, @@ -72,7 +73,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l { "ct|collectionType=", "collection type to use (default is " + typeof(Collection<>).FullName + ")", v => collectionType = v == null ? typeof(Collection<>) : Type.GetType(v, true) }, { "cit|collectionImplementationType=", "the default collection type implementation to use (default is null)", v => collectionImplementationType = v == null ? null : Type.GetType(v, true) }, { "ctro|codeTypeReferenceOptions=", "the default CodeTypeReferenceOptions Flags to use (default is unset; can be: {GlobalReference, GenericTypeParameter})", v => codeTypeReferenceOptions = v == null ? default(CodeTypeReferenceOptions) : (CodeTypeReferenceOptions)Enum.Parse(typeof(CodeTypeReferenceOptions), v, false) }, - { "tvpn|textValuePropertyName=", "the name of the property that holds the text value of an element (default is Value)", v => textValuePropertyName = v } + { "tvpn|textValuePropertyName=", "the name of the property that holds the text value of an element (default is Value)", v => textValuePropertyName = v }, + { "dst|debuggerStepThrough", "generate DebuggerStepThroughAttribute (default is enabled)", v => generateDebuggerStepThroughAttribute = v != null } }; var files = options.Parse(args); @@ -113,7 +115,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l CollectionType = collectionType, CollectionImplementationType = collectionImplementationType, CodeTypeReferenceOptions = codeTypeReferenceOptions, - TextValuePropertyName = textValuePropertyName + TextValuePropertyName = textValuePropertyName, + GenerateDebuggerStepThroughAttribute = generateDebuggerStepThroughAttribute }; if (pclCompatible) @@ -121,6 +124,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l generator.UseXElementForAny = true; generator.GenerateDesignerCategoryAttribute = false; generator.GenerateSerializableAttribute = false; + generator.GenerateDebuggerStepThroughAttribute = false; generator.DataAnnotationMode = DataAnnotationMode.None; } diff --git a/XmlSchemaClassGenerator/Generator.cs b/XmlSchemaClassGenerator/Generator.cs index b8f5807a..c327d19b 100644 --- a/XmlSchemaClassGenerator/Generator.cs +++ b/XmlSchemaClassGenerator/Generator.cs @@ -103,6 +103,12 @@ public bool GenerateSerializableAttribute set { _configuration.GenerateSerializableAttribute = value; } } + public bool GenerateDebuggerStepThroughAttribute + { + get { return _configuration.GenerateDebuggerStepThroughAttribute; } + set { _configuration.GenerateDebuggerStepThroughAttribute = value; } + } + public bool GenerateDesignerCategoryAttribute { get { return _configuration.GenerateDesignerCategoryAttribute; } @@ -772,6 +778,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM { var properties = new List(); var order = 0; + var count = 0; foreach (var item in items) { PropertyModel property = null; @@ -802,6 +809,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM } var propertyName = ToTitleCase(element.QualifiedName.Name); + propertyName = CreatePrefix(count, propertyName); if (propertyName == typeModel.Name) { propertyName += "Property"; // member names cannot be the same as their enclosing type @@ -811,7 +819,8 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM { OwningType = typeModel, XmlSchemaName = element.QualifiedName, - Name = propertyName, + Name = propertyName, // TODO: Name = originalName, + // TODO: OrderName = propertyName, Type = CreateTypeModel(source, element.ElementSchemaType, elementQualifiedName), IsNillable = element.IsNillable, IsNullable = item.MinOccurs < 1.0m, @@ -869,11 +878,22 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM properties.Add(property); } + + count++; } return properties; } + private static string CreatePrefix(int count, string propertyName) + { + if ((char)('a' + count) <= 'z') + propertyName = (char)('a' + count) + "_" + propertyName; + else + propertyName = "z" + (char)('a' + (count - 26)) + "_" + propertyName; + return propertyName; + } + private NamespaceModel CreateNamespaceModel(Uri source, XmlQualifiedName qualifiedName) { NamespaceModel namespaceModel = null; diff --git a/XmlSchemaClassGenerator/GeneratorConfiguration.cs b/XmlSchemaClassGenerator/GeneratorConfiguration.cs index abf55c49..2d23919e 100644 --- a/XmlSchemaClassGenerator/GeneratorConfiguration.cs +++ b/XmlSchemaClassGenerator/GeneratorConfiguration.cs @@ -83,6 +83,10 @@ public GeneratorConfiguration() /// public bool GenerateSerializableAttribute { get; set; } /// + /// Generate the DebuggerStepThroughAttribute? + /// + public bool GenerateDebuggerStepThroughAttribute { get; set; } + /// /// Generate the DesignerCategoryAttribute? /// public bool GenerateDesignerCategoryAttribute { get; set; } diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index f842388e..781e5d03 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -361,8 +361,10 @@ public override CodeTypeDeclaration Generate() classDeclaration.Members.Add(text); } - classDeclaration.CustomAttributes.Add( - new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerStepThroughAttribute), Configuration.CodeTypeReferenceOptions))); + if (Configuration.GenerateDebuggerStepThroughAttribute) + classDeclaration.CustomAttributes.Add( + new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerStepThroughAttribute), Configuration.CodeTypeReferenceOptions))); + if (Configuration.GenerateDesignerCategoryAttribute) { classDeclaration.CustomAttributes.Add( @@ -864,7 +866,10 @@ private IEnumerable GetAttributes(bool isArray) { if (IsAny) { - attributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyAttributeAttribute), Configuration.CodeTypeReferenceOptions))); + var anyAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyElementAttribute), Configuration.CodeTypeReferenceOptions)); + if (Order != null) + anyAttribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(Order.Value))); + attributes.Add(anyAttribute); } else { From 2d4a3f0cc014d52641f0e09469a9dccc964c4cc7 Mon Sep 17 00:00:00 2001 From: Henrik Fuchs Date: Thu, 11 May 2017 09:38:33 +0200 Subject: [PATCH 2/3] Reverted some changes --- XmlSchemaClassGenerator/Generator.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/XmlSchemaClassGenerator/Generator.cs b/XmlSchemaClassGenerator/Generator.cs index c327d19b..bece22f1 100644 --- a/XmlSchemaClassGenerator/Generator.cs +++ b/XmlSchemaClassGenerator/Generator.cs @@ -778,7 +778,6 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM { var properties = new List(); var order = 0; - var count = 0; foreach (var item in items) { PropertyModel property = null; @@ -809,7 +808,6 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM } var propertyName = ToTitleCase(element.QualifiedName.Name); - propertyName = CreatePrefix(count, propertyName); if (propertyName == typeModel.Name) { propertyName += "Property"; // member names cannot be the same as their enclosing type @@ -819,8 +817,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM { OwningType = typeModel, XmlSchemaName = element.QualifiedName, - Name = propertyName, // TODO: Name = originalName, - // TODO: OrderName = propertyName, + Name = propertyName, Type = CreateTypeModel(source, element.ElementSchemaType, elementQualifiedName), IsNillable = element.IsNillable, IsNullable = item.MinOccurs < 1.0m, @@ -878,22 +875,11 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM properties.Add(property); } - - count++; } return properties; } - private static string CreatePrefix(int count, string propertyName) - { - if ((char)('a' + count) <= 'z') - propertyName = (char)('a' + count) + "_" + propertyName; - else - propertyName = "z" + (char)('a' + (count - 26)) + "_" + propertyName; - return propertyName; - } - private NamespaceModel CreateNamespaceModel(Uri source, XmlQualifiedName qualifiedName) { NamespaceModel namespaceModel = null; From 0a439077e48a41ecf8a977de751f6810381b32bf Mon Sep 17 00:00:00 2001 From: Henrik Fuchs Date: Thu, 11 May 2017 13:12:27 +0200 Subject: [PATCH 3/3] Fix Order for AnyAttribute --- XmlSchemaClassGenerator/TypeModel.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 781e5d03..7f45f5e4 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -866,7 +866,7 @@ private IEnumerable GetAttributes(bool isArray) { if (IsAny) { - var anyAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyElementAttribute), Configuration.CodeTypeReferenceOptions)); + var anyAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyAttributeAttribute), Configuration.CodeTypeReferenceOptions)); if (Order != null) anyAttribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(Order.Value))); attributes.Add(anyAttribute); @@ -881,7 +881,10 @@ private IEnumerable GetAttributes(bool isArray) { if (IsAny) { - attributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyElementAttribute), Configuration.CodeTypeReferenceOptions))); + var anyAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyElementAttribute), Configuration.CodeTypeReferenceOptions)); + if (Order != null) + anyAttribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(Order.Value))); + attributes.Add(anyAttribute); } else {