Skip to content

Commit

Permalink
Retrieve attributes only once in SystemTextJsonReflectionService.Gene…
Browse files Browse the repository at this point in the history
…rateProperties
  • Loading branch information
lahma committed Nov 24, 2024
1 parent 1a7c0ec commit fa484cf
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/NJsonSchema/Generation/SystemTextJsonReflectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public override void GenerateProperties(JsonSchema schema, ContextualType contex
}

var propertyIgnored = false;
var jsonIgnoreAttribute = accessorInfo
.GetAttributes(true)
.FirstAssignableToTypeNameOrDefault("System.Text.Json.Serialization.JsonIgnoreAttribute", TypeNameStyle.FullName);
var attributes = accessorInfo.GetAttributes(true).ToArray();
var jsonIgnoreAttribute = attributes.FirstAssignableToTypeNameOrDefault("System.Text.Json.Serialization.JsonIgnoreAttribute", TypeNameStyle.FullName);

if (jsonIgnoreAttribute != null)
{
Expand All @@ -65,9 +64,8 @@ public override void GenerateProperties(JsonSchema schema, ContextualType contex

var ignored = propertyIgnored
|| schemaGenerator.IsPropertyIgnoredBySettings(accessorInfo)
|| accessorInfo.GetAttributes(true)
.FirstAssignableToTypeNameOrDefault("System.Text.Json.Serialization.JsonExtensionDataAttribute", TypeNameStyle.FullName) != null
|| settings.ExcludedTypeNames.Contains(accessorInfo.AccessorType.Type.FullName);
|| attributes.FirstAssignableToTypeNameOrDefault("System.Text.Json.Serialization.JsonExtensionDataAttribute", TypeNameStyle.FullName) != null
|| Array.IndexOf(settings.ExcludedTypeNames, accessorInfo.AccessorType.Type.FullName) != -1;

if (!ignored)
{
Expand All @@ -87,9 +85,7 @@ public override void GenerateProperties(JsonSchema schema, ContextualType contex
}
}

var requiredAttribute = accessorInfo
.GetAttributes(true)
.FirstAssignableToTypeNameOrDefault("System.ComponentModel.DataAnnotations.RequiredAttribute");
var requiredAttribute = attributes.FirstAssignableToTypeNameOrDefault("System.ComponentModel.DataAnnotations.RequiredAttribute");

var isDataContractMemberRequired = schemaGenerator.GetDataMemberAttribute(accessorInfo, contextualType.Type)?.IsRequired == true;

Expand Down

0 comments on commit fa484cf

Please # to comment.