From 67e68297e2b31fca8147997dc4eec0ff32567e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 19 May 2020 00:57:52 +0300 Subject: [PATCH] Create GetInputFormatOrNull extension method for ObjectExtensionPropertyInfo --- ...UiObjectExtensionPropertyInfoExtensions.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs new file mode 100644 index 0000000000..bac7787028 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs @@ -0,0 +1,44 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace Volo.Abp.ObjectExtending +{ + public static class MvcUiObjectExtensionPropertyInfoExtensions + { + private static readonly Type[] DateTypes = new[] + { + typeof(DateTime), typeof(DateTimeOffset) + }; + + public static string GetInputFormatOrNull(this ObjectExtensionPropertyInfo property) + { + if (IsDate(property)) + { + return "{0:yyyy-MM-dd}"; + } + + return null; + } + + private static bool IsDate(ObjectExtensionPropertyInfo property) + { + if (!DateTypes.Contains(property.Type)) + { + return false; + } + + var dataTypeAttribute = property + .Attributes + .OfType() + .FirstOrDefault(); + + if (dataTypeAttribute == null) + { + return false; + } + + return dataTypeAttribute.DataType == DataType.Date; + } + } +}