Commit 8f9dad6c authored by yangxiaodong's avatar yangxiaodong

modify how to determine complex types.

parent bf5372d2
...@@ -72,7 +72,26 @@ namespace DotNetCore.CAP.Infrastructure ...@@ -72,7 +72,26 @@ namespace DotNetCore.CAP.Infrastructure
public static bool IsComplexType(Type type) 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));
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment