diff options
Diffstat (limited to 'src/Mvc/Mvc.ApiExplorer/src/EndpointModelMetadata.cs')
-rw-r--r-- | src/Mvc/Mvc.ApiExplorer/src/EndpointModelMetadata.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Mvc/Mvc.ApiExplorer/src/EndpointModelMetadata.cs b/src/Mvc/Mvc.ApiExplorer/src/EndpointModelMetadata.cs index 4ad1b72396..3fd46f1798 100644 --- a/src/Mvc/Mvc.ApiExplorer/src/EndpointModelMetadata.cs +++ b/src/Mvc/Mvc.ApiExplorer/src/EndpointModelMetadata.cs @@ -51,4 +51,20 @@ internal sealed class EndpointModelMetadata : ModelMetadata public override string? TemplateHint { get; } public override bool ValidateChildren { get; } public override IReadOnlyList<object> ValidatorMetadata { get; } = Array.Empty<object>(); + + public static Type GetDisplayType(Type type) + { + var underlyingType = Nullable.GetUnderlyingType(type) ?? type; + return underlyingType.IsPrimitive + // Those additional types have TypeConverter or TryParse and are not primitives + // but should not be considered string in the metadata + || underlyingType == typeof(DateTime) + || underlyingType == typeof(DateTimeOffset) + || underlyingType == typeof(DateOnly) + || underlyingType == typeof(TimeOnly) + || underlyingType == typeof(TimeSpan) + || underlyingType == typeof(decimal) + || underlyingType == typeof(Guid) + || underlyingType == typeof(Uri) ? type : typeof(string); + } } |