Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Move method IsSimpleType to CommonHelper
support87e578ba3bf2
diff --git a/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs b/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.csindex 0861fade8..8ee83a3fa 100644--- a/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs+++ b/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs@@ -1,5 +1,6 @@using FluentValidation;using FluentValidation.AspNetCore;+using Grand.SharedKernel.Extensions;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Filters;@@ -39,7 +40,7 @@ namespace Grand.Infrastructure.Validatorsreturn;}- foreach (var argument in context.ActionArguments.Where(x => !IsSimpleType(x.Value?.GetType())))+ foreach (var argument in context.ActionArguments.Where(x => !CommonHelper.IsSimpleType(x.Value?.GetType()))){Type genericType = typeof(IValidator<>).MakeGenericType(argument.Value!.GetType());var validator = (IValidator)_serviceProvider.GetService(genericType);@@ -57,28 +58,6 @@ namespace Grand.Infrastructure.Validatorsawait next();}-- private static bool IsSimpleType(Type? type)- {- if (type == null)- return true;-- return- type.IsPrimitive ||- new Type[] {- typeof(string),- typeof(decimal),- typeof(DateTime),- typeof(DateTimeOffset),- typeof(TimeSpan),- typeof(Guid)- }.Contains(type) ||- type.IsEnum ||- Convert.GetTypeCode(type) != TypeCode.Object ||- (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) && IsSimpleType(type.GetGenericArguments()[0]))- ;- }-#endregion}}\ No newline at end of filediff --git a/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs b/src/Core/Grand.SharedKernel/Extensions/CommonHelper.csindex d71c34aab..142289e80 100644--- a/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs+++ b/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs@@ -159,7 +159,32 @@ namespace Grand.SharedKernel.Extensions}return true;}-++ /// <summary>+ /// Check if type is simple+ /// </summary>+ /// <param name="type"></param>+ /// <returns></returns>+ public static bool IsSimpleType(Type? type)+ {+ if (type == null)+ return true;++ return+ type.IsPrimitive ||+ new Type[] {+ typeof(string),+ typeof(decimal),+ typeof(DateTime),+ typeof(DateTimeOffset),+ typeof(TimeSpan),+ typeof(Guid)+ }.Contains(type) ||+ type.IsEnum ||+ Convert.GetTypeCode(type) != TypeCode.Object ||+ (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) && IsSimpleType(type.GetGenericArguments()[0]))+ ;+ }/// <summary>/// Converts a value to a destination type./// </summary>