From 485d990d0dd79c2827b46c83b5dca4d36518f5a0 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Tue, 9 Nov 2021 16:49:41 +0100 Subject: [PATCH] Fix sonarcloud issues --- XmlSchemaClassGenerator/ModelBuilder.cs | 12 ++++++------ XmlSchemaClassGenerator/OutputWriter.cs | 2 +- XmlSchemaClassGenerator/TypeModel.cs | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs index 06ce6e39..d0d73b62 100644 --- a/XmlSchemaClassGenerator/ModelBuilder.cs +++ b/XmlSchemaClassGenerator/ModelBuilder.cs @@ -158,14 +158,14 @@ private void RemoveDuplicateInterfaceProperties() foreach (var interfaceModel in Types.Values.OfType()) { var parentProperties = interfaceModel.Properties.ToList(); - foreach (var baseInterfaceType in interfaceModel.AllDerivedReferenceTypes().OfType()) + foreach (var baseInterfaceTypeProperties in interfaceModel.AllDerivedReferenceTypes().OfType().Select(i => i.Properties)) { foreach (var parentProperty in parentProperties) { - var baseProperties = baseInterfaceType.Properties.ToList(); + var baseProperties = baseInterfaceTypeProperties.ToList(); foreach (var baseProperty in baseProperties.Where(baseProperty => parentProperty.Name == baseProperty.Name && parentProperty.Type.Name == baseProperty.Type.Name)) { - baseInterfaceType.Properties.Remove(baseProperty); + baseInterfaceTypeProperties.Remove(baseProperty); } } } @@ -223,10 +223,10 @@ private void ResolveDependencies(XmlSchema schema, List dependencyOrd if (imports.Any()) { - foreach (var import in imports) + foreach (var importSchema in imports.Select(i => i.Schema)) { - if (import.Schema != null) - ResolveDependencies(import.Schema, dependencyOrder, seenSchemas); + if (importSchema != null) + ResolveDependencies(importSchema, dependencyOrder, seenSchemas); } } diff --git a/XmlSchemaClassGenerator/OutputWriter.cs b/XmlSchemaClassGenerator/OutputWriter.cs index 4bcd1cf5..61fdb3ff 100644 --- a/XmlSchemaClassGenerator/OutputWriter.cs +++ b/XmlSchemaClassGenerator/OutputWriter.cs @@ -33,7 +33,7 @@ protected void Write(TextWriter writer, CodeCompileUnit cu) /// A wrapper around that removes semicolons after a closing brace /// due to a bug in CodeDom and auto-properties /// - private class SemicolonRemovalTextWriter : TextWriter + private sealed class SemicolonRemovalTextWriter : TextWriter { private readonly TextWriter _other; diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 6f579eb1..408f4045 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -1251,30 +1251,30 @@ private IEnumerable GetAttributes(bool isArray, TypeMo attributes.Add(arrayAttribute); } - foreach (var attribute in attributes) + foreach (var args in attributes.Select(a => a.Arguments)) { - bool namespacePrecalculated = attribute.Arguments.OfType().Any(a => a.Name == "Namespace"); + bool namespacePrecalculated = args.OfType().Any(a => a.Name == "Namespace"); if (!namespacePrecalculated) { if (XmlNamespace != null) { - attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(XmlNamespace))); + args.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(XmlNamespace))); } if (Form == XmlSchemaForm.Qualified && IsAttribute) { if (XmlNamespace == null) { - attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(OwningType.XmlSchemaName.Namespace))); + args.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(OwningType.XmlSchemaName.Namespace))); } - attribute.Arguments.Add(new CodeAttributeArgument("Form", + args.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(CodeUtilities.CreateTypeReference(typeof(XmlSchemaForm), Configuration)), "Qualified"))); } else if ((Form == XmlSchemaForm.Unqualified || Form == XmlSchemaForm.None) && !IsAttribute && !IsAny && XmlNamespace == null) { - attribute.Arguments.Add(new CodeAttributeArgument("Form", + args.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(CodeUtilities.CreateTypeReference(typeof(XmlSchemaForm), Configuration)), "Unqualified"))); } @@ -1282,7 +1282,7 @@ private IEnumerable GetAttributes(bool isArray, TypeMo if (IsNillable && !(IsCollection && Type is SimpleModel m && m.ValueType.IsValueType) && !(IsNullable && Configuration.DoNotForceIsNullable)) { - attribute.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression(true))); + args.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression(true))); } if (Type is SimpleModel simpleModel && simpleModel.UseDataTypeAttribute) @@ -1295,7 +1295,7 @@ private IEnumerable GetAttributes(bool isArray, TypeMo if (name.Namespace == XmlSchema.Namespace && name.Name != "anySimpleType") { var dataType = new CodeAttributeArgument("DataType", new CodePrimitiveExpression(name.Name)); - attribute.Arguments.Add(dataType); + args.Add(dataType); break; } else