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 Jun 8, 2022
1 parent 50adb75 commit 7b2b6c7
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,16 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi
member.Type = typeReference;
}

member.Name += backingField != null
? GetAccessors(member.Name, backingField.Name, IsCollection || isArray ? PropertyValueTypeCode.Array : propertyType.GetPropertyValueTypeCode(), isPrivateSetter, withDataBinding)
: $" {{ get; {(isPrivateSetter ? "private " : string.Empty)}set; }}"; // hack to generate automatic property
if (backingField != null)
{
var propertyValueTypeCode = IsCollection || isArray ? PropertyValueTypeCode.Array : propertyType.GetPropertyValueTypeCode();
member.Name += GetAccessors(member.Name, backingField.Name, propertyValueTypeCode, isPrivateSetter, withDataBinding);
}
else
{
var privateSetter = isPrivateSetter ? "private " : string.Empty;
member.Name += $" {{ get; {privateSetter}set; }}"; // hack to generate automatic property
}
}
else
{
Expand Down Expand Up @@ -1105,7 +1112,7 @@ public class EnumValueModel
public class EnumModel : TypeModel
{
public List<EnumValueModel> Values { get; set; } = new();

public EnumModel(GeneratorConfiguration configuration) : base(configuration) { }
public override CodeTypeDeclaration Generate()
{
Expand Down Expand Up @@ -1232,8 +1239,21 @@ public override CodeTypeReference GetReferenceFor(NamespaceModel referencingName
{
var collectionType = forInit ? (Configuration.CollectionImplementationType ?? Configuration.CollectionType) : Configuration.CollectionType;

type = collectionType.IsGenericType ? collectionType.MakeGenericType(type)
: collectionType == typeof(Array) ? type.MakeArrayType() : collectionType;
if (collectionType.IsGenericType)
{
type = collectionType.MakeGenericType(type);
}
else
{
if (collectionType == typeof(Array))
{
type = type.MakeArrayType();
}
else
{
type = collectionType;
}
}
}

return CodeUtilities.CreateTypeReference(type, Configuration);
Expand Down Expand Up @@ -1270,7 +1290,13 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
}
else if (type == typeof(bool) && !string.IsNullOrWhiteSpace(defaultString))
{
return new CodePrimitiveExpression(defaultString == "0" ? false : defaultString == "1" ? true : Convert.ChangeType(defaultString, ValueType));
var val = defaultString switch
{
"0" => false,
"1" => true,
_ => Convert.ChangeType(defaultString, ValueType)
};
return new CodePrimitiveExpression(val);
}
else if (type == typeof(byte[]) && defaultString != null)
{
Expand Down

0 comments on commit 7b2b6c7

Please sign in to comment.