Skip to content

Commit

Permalink
Fix sonarcloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Nov 9, 2021
1 parent 2ede85a commit 485d990
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ private void RemoveDuplicateInterfaceProperties()
foreach (var interfaceModel in Types.Values.OfType<InterfaceModel>())
{
var parentProperties = interfaceModel.Properties.ToList();
foreach (var baseInterfaceType in interfaceModel.AllDerivedReferenceTypes().OfType<InterfaceModel>())
foreach (var baseInterfaceTypeProperties in interfaceModel.AllDerivedReferenceTypes().OfType<InterfaceModel>().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);
}
}
}
Expand Down Expand Up @@ -223,10 +223,10 @@ private void ResolveDependencies(XmlSchema schema, List<XmlSchema> 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator/OutputWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void Write(TextWriter writer, CodeCompileUnit cu)
/// A wrapper around <see cref="TextWriter"/> that removes semicolons after a closing brace
/// due to a bug in CodeDom and auto-properties
/// </summary>
private class SemicolonRemovalTextWriter : TextWriter
private sealed class SemicolonRemovalTextWriter : TextWriter
{
private readonly TextWriter _other;

Expand Down
16 changes: 8 additions & 8 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,38 +1251,38 @@ private IEnumerable<CodeAttributeDeclaration> 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<CodeAttributeArgument>().Any(a => a.Name == "Namespace");
bool namespacePrecalculated = args.OfType<CodeAttributeArgument>().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")));
}
}

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)
Expand All @@ -1295,7 +1295,7 @@ private IEnumerable<CodeAttributeDeclaration> 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
Expand Down

0 comments on commit 485d990

Please sign in to comment.