Skip to content

Commit

Permalink
Cosmetic cleanup as suggested by the IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed May 16, 2024
1 parent 1ce9552 commit d1806f6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Tingle.AspNetCore.JsonPatch/Internal/ParsedPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ private static string[] ParsePath(string path)
strings.Add(sb.ToString());
}

return strings.ToArray();
return [.. strings];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public InheritDocSchemaFilter(SwaggerGenOptions options, params Type[] excludedT
/// <param name="context"><see cref="SchemaFilterContext"/>.</param>
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
if (excludedTypes.Any() && excludedTypes.Contains(context.Type)) return;
if (excludedTypes.Length != 0 && excludedTypes.Contains(context.Type)) return;

// Try to apply a description for inherited types.
var memberName = XmlCommentsNodeNameHelper.GetMemberNameForType(context.Type);
Expand Down Expand Up @@ -98,10 +98,9 @@ private void ApplyPropertyComments(OpenApiSchema propertySchema, MemberInfo memb
{
var memberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(memberInfo);

if (!inheritedDocs.ContainsKey(memberName)) return;
if (excludedTypes.Any() && excludedTypes.Contains(((PropertyInfo)memberInfo).PropertyType)) return;
if (excludedTypes.Length != 0 && excludedTypes.Contains(((PropertyInfo)memberInfo).PropertyType)) return;
if (!inheritedDocs.TryGetValue(memberName, out string? cref)) return;

var cref = inheritedDocs[memberName];
var target = GetTargetRecursive(memberInfo, cref);

var targetXmlNode = GetMemberXmlNode(XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(target));
Expand Down Expand Up @@ -184,7 +183,7 @@ private void ApplyPropertyComments(OpenApiSchema propertySchema, MemberInfo memb
{
var targets = type.GetInterfaces();
if (type.BaseType is not null && type.BaseType != typeof(object))
targets = targets.Append(type.BaseType).ToArray();
targets = [.. targets, type.BaseType];

// Try to find the target, if one is declared.
if (!string.IsNullOrEmpty(cref))
Expand Down
4 changes: 2 additions & 2 deletions src/Tingle.Extensions.DataAnnotations/RecursiveValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static bool TryValidateObjectRecursive(object instance,
bool result = TryValidateObject(instance, validationResults, validationContextItems);

var properties = instance.GetType().GetProperties().Where(prop => prop.CanRead
&& !prop.GetCustomAttributes(typeof(SkipRecursiveValidationAttribute), false).Any()
&& prop.GetCustomAttributes(typeof(SkipRecursiveValidationAttribute), false).Length == 0
&& prop.GetIndexParameters().Length == 0).ToList();

foreach (var property in properties)
Expand Down Expand Up @@ -169,7 +169,7 @@ private static void ValidateObjectRecursive(object instance,
ValidateObject(instance, validationContextItems);

var properties = instance.GetType().GetProperties().Where(prop => prop.CanRead
&& !prop.GetCustomAttributes(typeof(SkipRecursiveValidationAttribute), false).Any()
&& prop.GetCustomAttributes(typeof(SkipRecursiveValidationAttribute), false).Length == 0
&& prop.GetIndexParameters().Length == 0).ToList();

foreach (var property in properties)
Expand Down
2 changes: 1 addition & 1 deletion src/Tingle.Extensions.JsonPatch/Internal/ParsedPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ private static string[] ParsePath(string path)
strings.Add(sb.ToString());
}

return strings.ToArray();
return [.. strings];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void Works_For_StringArray(string value, bool expected)
[InlineData(false, "green", "BLUE", "yellow")]
public void Works_For_CaseSensitiveStrings(bool expected, params string[] value)
{
var obj = new TestModel5(value.ToList());
var obj = new TestModel5([.. value]);
var context = new ValidationContext(obj);
var results = new List<ValidationResult>();
var actual = Validator.TryValidateObject(obj, context, results, true);
Expand Down

0 comments on commit d1806f6

Please sign in to comment.