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 Jul 17, 2023
1 parent 45e06bc commit 2a4d8c1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static void DeserializeSampleXml(ITestOutputHelper output, string patter

foreach (var rootElement in set.GlobalElements.Values.Cast<XmlSchemaElement>().Where(e =>
!e.IsAbstract
&& !(e.ElementSchemaType is XmlSchemaSimpleType)
&& e.ElementSchemaType is not XmlSchemaSimpleType
&& e.ElementSchemaType.QualifiedName != AnyType))
{
var type = FindType(assembly, rootElement.QualifiedName);
Expand Down
8 changes: 4 additions & 4 deletions XmlSchemaClassGenerator/CodeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ private static Type GetUnionType(GeneratorConfiguration configuration, XmlSchema
if (baseMemberEffectiveTypes.Distinct().Count() == 1) return baseMemberEffectiveTypes[0];

// all member types are integer types
if (baseMemberEffectiveTypes.All(t => intTypes.Contains(t)))
if (baseMemberEffectiveTypes.TrueForAll(t => intTypes.Contains(t)))
{
var maxTypeIndex = baseMemberEffectiveTypes.Max(t => Array.IndexOf(intTypes, t));
var maxType = intTypes[maxTypeIndex];
// if the max type is signed and the corresponding unsigned type is also in the set we have to use the next higher type
if (maxTypeIndex % 2 == 1 && baseMemberEffectiveTypes.Any(t => Array.IndexOf(intTypes, t) == maxTypeIndex - 1))
if (maxTypeIndex % 2 == 1 && baseMemberEffectiveTypes.Exists(t => Array.IndexOf(intTypes, t) == maxTypeIndex - 1))
return intTypes[maxTypeIndex + 1];
return maxType;
}

// all member types are float/double/decimal
if (baseMemberEffectiveTypes.All(t => decimalTypes.Contains(t)))
if (baseMemberEffectiveTypes.TrueForAll(t => decimalTypes.Contains(t)))
{
var maxTypeIndex = baseMemberEffectiveTypes.Max(t => Array.IndexOf(decimalTypes, t));
var maxType = decimalTypes[maxTypeIndex];
Expand Down Expand Up @@ -342,7 +342,7 @@ public static KeyValuePair<NamespaceKey, string> ParseNamespace(string nsArg, st
);

public static bool IsUsingNamespace(string namespaceName, GeneratorConfiguration conf)
=> UsingNamespaces.Any(n => n.Namespace == namespaceName && n.Condition(conf));
=> UsingNamespaces.Exists(n => n.Namespace == namespaceName && n.Condition(conf));

public static CodeTypeReference CreateTypeReference(Type type, GeneratorConfiguration conf)
{
Expand Down
10 changes: 5 additions & 5 deletions XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private void PromoteInterfacePropertiesToCollection()
var derivedProperties = interfaceModel.AllDerivedReferenceTypes().SelectMany(t => t.Properties)
.Where(p => p.Name == interfaceProperty.Name || p.OriginalPropertyName == interfaceProperty.Name).ToList();

if (derivedProperties.Any(p => p.IsCollection))
if (derivedProperties.Exists(p => p.IsCollection))
{
foreach (var derivedProperty in derivedProperties.Where(p => !p.IsCollection))
derivedProperty.IsCollection = true;
Expand Down Expand Up @@ -636,7 +636,7 @@ XmlSchemaSimpleTypeUnion typeUnion when AllMembersHaveFacets(typeUnion, out base

// If a union has enum restrictions, there must be an enum restriction in all parts of the union
// If there are other restrictions mixed into the enumeration values, we'll generate a string to play it safe.
if (enumFacets.Count > 0 && (baseFacets is null || baseFacets.All(fs => fs.OfType<XmlSchemaEnumerationFacet>().Any())) && !_configuration.EnumAsString)
if (enumFacets.Count > 0 && (baseFacets is null || baseFacets.TrueForAll(fs => fs.OfType<XmlSchemaEnumerationFacet>().Any())) && !_configuration.EnumAsString)
return CreateEnumModel(simpleType, enumFacets);

restrictions = CodeUtilities.GetRestrictions(facets, simpleType, _configuration).Where(r => r != null).Sanitize().ToList();
Expand Down Expand Up @@ -698,7 +698,7 @@ private EnumModel CreateEnumModel(XmlSchemaSimpleType simpleType, List<XmlSchema
value.Documentation.AddRange(valueDocs);

value.IsDeprecated = facet.Annotation?.Items.OfType<XmlSchemaAppInfo>()
.Any(a => a.Markup.Any(m => m.Name == "annox:annotate" && m.HasChildNodes && m.FirstChild.Name == "jl:Deprecated")) == true;
.Any(a => Array.Exists(a.Markup, m => m.Name == "annox:annotate" && m.HasChildNodes && m.FirstChild.Name == "jl:Deprecated")) == true;

enumModel.Values.Add(value);
}
Expand Down Expand Up @@ -898,15 +898,15 @@ private IEnumerable<PropertyModel> CreatePropertiesForElements(Uri source, TypeM
// Discard duplicate property names. This is most likely due to:
// - Choice or
// - Element and attribute with the same name
if (property != null && !properties.Any(p => p.Name == property.Name))
if (property != null && !properties.Exists(p => p.Name == property.Name))
{
var itemDocs = GetDocumentation(item.XmlParticle);
property.Documentation.AddRange(itemDocs);

if (_configuration.EmitOrder)
property.Order = order++;

property.IsDeprecated = itemDocs.Any(d => d.Text.StartsWith("DEPRECATED"));
property.IsDeprecated = itemDocs.Exists(d => d.Text.StartsWith("DEPRECATED"));

properties.Add(property);
}
Expand Down
12 changes: 7 additions & 5 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public IEnumerable<ReferenceTypeModel> AllDerivedReferenceTypes(List<ReferenceTy

public class ClassModel : ReferenceTypeModel
{
public override bool IsRedefined => DerivedTypes.Any(d => d.XmlSchemaType?.Parent is XmlSchemaRedefine);
public override bool IsRedefined => DerivedTypes.Exists(d => d.XmlSchemaType?.Parent is XmlSchemaRedefine);
public bool IsAbstract { get; set; }
public bool IsMixed { get; set; }
public bool IsSubstitution { get; set; }
Expand Down Expand Up @@ -391,7 +391,7 @@ public override CodeTypeDeclaration Generate()
var propName = "Text";

// To not collide with any existing members
for (var propertyIndex = 1; Properties.Any(x => x.Name.Equals(propName, StringComparison.Ordinal)) || propName.Equals(classDeclaration.Name, StringComparison.Ordinal); propertyIndex++)
for (var propertyIndex = 1; Properties.Exists(x => x.Name.Equals(propName, StringComparison.Ordinal)) || propName.Equals(classDeclaration.Name, StringComparison.Ordinal); propertyIndex++)
{
propName = $"Text_{propertyIndex}";
}
Expand Down Expand Up @@ -748,7 +748,9 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi
else
{
var defaultValueExpression = propertyType.GetDefaultValueFor(DefaultValue, IsAttribute);
backingField.InitExpression = defaultValueExpression;

if (backingField != null)
backingField.InitExpression = defaultValueExpression;

member.Type = IsNillableValueType ? NullableTypeRef(typeReference) : typeReference;

Expand Down Expand Up @@ -1384,7 +1386,7 @@ protected IEnumerable<CodeCommentStatement> GetComments(IList<DocumentationModel
yield return new CodeCommentStatement("<summary>", true);

foreach (var doc in docs
.Where(d => string.IsNullOrEmpty(d.Language) || Configuration.CommentLanguages.Any(l => d.Language.StartsWith(l, StringComparison.OrdinalIgnoreCase)))
.Where(d => string.IsNullOrEmpty(d.Language) || Configuration.CommentLanguages.Exists(l => d.Language.StartsWith(l, StringComparison.OrdinalIgnoreCase)))
.OrderBy(d => d.Language))
{
var text = doc.Text;
Expand All @@ -1399,7 +1401,7 @@ protected void AddDescription(CodeAttributeDeclarationCollection attributes, IEn
{
if (!Configuration.GenerateDescriptionAttribute || DisableComments || !docs.Any()) return;

var doc = GetSingleDoc(docs.Where(d => string.IsNullOrEmpty(d.Language) || Configuration.CommentLanguages.Any(l => d.Language.StartsWith(l, StringComparison.OrdinalIgnoreCase))));
var doc = GetSingleDoc(docs.Where(d => string.IsNullOrEmpty(d.Language) || Configuration.CommentLanguages.Exists(l => d.Language.StartsWith(l, StringComparison.OrdinalIgnoreCase))));

if (doc != null)
{
Expand Down

0 comments on commit 2a4d8c1

Please sign in to comment.