Skip to content

Commit

Permalink
Removed extension PropertyInfo.HasAttribute in favor of builtin IsDef…
Browse files Browse the repository at this point in the history
…ined
  • Loading branch information
jcracknell committed Apr 14, 2024
1 parent a6dba76 commit 638d825
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private IEnumerable<DataProperty> GetDataPropertiesFor(Type objectType, out Type
return
(property.IsPubliclyReadable() || property.IsPubliclyWritable()) &&
!(property.GetIndexParameters().Any()) &&
!(property.HasAttribute<JsonIgnoreAttribute>() && isIgnoredViaNet5Attribute) &&
!(property.HasAttribute<SwaggerIgnoreAttribute>()) &&
!(property.IsDefined(typeof(JsonIgnoreAttribute)) && isIgnoredViaNet5Attribute) &&
!(property.IsDefined(typeof(SwaggerIgnoreAttribute))) &&
!(_serializerOptions.IgnoreReadOnlyProperties && !property.IsPubliclyWritable());
})
.OrderBy(property => property.DeclaringType.GetInheritanceChain().Length);
Expand All @@ -176,7 +176,7 @@ private IEnumerable<DataProperty> GetDataPropertiesFor(Type objectType, out Type

foreach (var propertyInfo in applicableProperties)
{
if (propertyInfo.HasAttribute<JsonExtensionDataAttribute>()
if (propertyInfo.IsDefined(typeof(JsonExtensionDataAttribute))
&& propertyInfo.PropertyType.IsConstructedFrom(typeof(IDictionary<,>), out Type constructedDictionary))
{
extensionDataType = constructedDictionary.GenericTypeArguments[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ namespace Swashbuckle.AspNetCore.SwaggerGen
{
public static class PropertyInfoExtensions
{
public static bool HasAttribute<TAttribute>(this PropertyInfo property)
where TAttribute : Attribute
{
return property.GetCustomAttribute<TAttribute>() != null;
}

public static bool IsPubliclyReadable(this PropertyInfo property)
{
return property.GetMethod?.IsPublic == true;
Expand Down

0 comments on commit 638d825

Please sign in to comment.