Browse Source

modify how to determine complex types.

master
yangxiaodong 7 years ago
parent
commit
8f9dad6cb4
1 changed files with 20 additions and 1 deletions
  1. +20
    -1
      src/DotNetCore.CAP/Infrastructure/Helper.cs

+ 20
- 1
src/DotNetCore.CAP/Infrastructure/Helper.cs View File

@@ -72,7 +72,26 @@ namespace DotNetCore.CAP.Infrastructure

public static bool IsComplexType(Type type)
{
return !TypeDescriptor.GetConverter(type).CanConvertFrom(typeof(string));
return !CanConvertFromString(type);
}

private static bool CanConvertFromString(Type destinationType)
{
destinationType = Nullable.GetUnderlyingType(destinationType) ?? destinationType;
return IsSimpleType(destinationType) ||
TypeDescriptor.GetConverter(destinationType).CanConvertFrom(typeof(string));
}

private static bool IsSimpleType(Type type)
{
return type.GetTypeInfo().IsPrimitive ||
type.Equals(typeof(decimal)) ||
type.Equals(typeof(string)) ||
type.Equals(typeof(DateTime)) ||
type.Equals(typeof(Guid)) ||
type.Equals(typeof(DateTimeOffset)) ||
type.Equals(typeof(TimeSpan)) ||
type.Equals(typeof(Uri));
}
}
}

Loading…
Cancel
Save