Browse Source
Remove IsNullable from ReflectionHelper and update usage
pull/24335/head
maliming
9 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
2 additions and
21 deletions
-
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs
-
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs
|
|
|
@ -8,26 +8,6 @@ namespace Volo.Abp.Reflection; |
|
|
|
//TODO: Consider to make internal
|
|
|
|
public static class ReflectionHelper |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Checks whether the property is nullable, including nullable reference types (NRT).
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="propertyInfo">Property info to check</param>
|
|
|
|
public static bool IsNullable(PropertyInfo propertyInfo) |
|
|
|
{ |
|
|
|
if (propertyInfo.PropertyType.IsValueType) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
#if NET6_0_OR_GREATER
|
|
|
|
var nullabilityInfoContext = new System.Reflection.NullabilityInfoContext(); |
|
|
|
var nullabilityInfo = nullabilityInfoContext.Create(propertyInfo); |
|
|
|
return nullabilityInfo.ReadState == System.Reflection.NullabilityState.Nullable; |
|
|
|
#else
|
|
|
|
return false; |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
//TODO: Ehhance summary
|
|
|
|
/// <summary>
|
|
|
|
/// Checks whether <paramref name="givenType"/> implements/inherits <paramref name="genericType"/>.
|
|
|
|
|
|
|
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using Volo.Abp.Http.ProxyScripting.Configuration; |
|
|
|
using Volo.Abp.Reflection; |
|
|
|
|
|
|
|
namespace Volo.Abp.Http.Modeling; |
|
|
|
|
|
|
|
@ -41,7 +42,7 @@ public class PropertyApiDescriptionModel |
|
|
|
Type = ApiTypeNameHelper.GetTypeName(propertyInfo.PropertyType), |
|
|
|
TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType), |
|
|
|
IsRequired = customAttributes.OfType<RequiredAttribute>().Any() || propertyInfo.GetCustomAttributesData().Any(attr => attr.AttributeType.Name == "RequiredMemberAttribute"), |
|
|
|
IsNullable = Volo.Abp.Reflection.ReflectionHelper.IsNullable(propertyInfo), |
|
|
|
IsNullable = TypeHelper.IsNullable(propertyInfo.PropertyType), |
|
|
|
Minimum = customAttributes.OfType<RangeAttribute>().Select(x => x.Minimum).FirstOrDefault()?.ToString(), |
|
|
|
Maximum = customAttributes.OfType<RangeAttribute>().Select(x => x.Maximum).FirstOrDefault()?.ToString(), |
|
|
|
MinLength = customAttributes.OfType<MinLengthAttribute>().FirstOrDefault()?.Length ?? customAttributes.OfType<StringLengthAttribute>().FirstOrDefault()?.MinimumLength, |
|
|
|
|