Просмотр исходного кода

modify how to determine complex types.

master
yangxiaodong 7 лет назад
Родитель
Сommit
8f9dad6cb4
1 измененных файлов: 20 добавлений и 1 удалений
  1. +20
    -1
      src/DotNetCore.CAP/Infrastructure/Helper.cs

+ 20
- 1
src/DotNetCore.CAP/Infrastructure/Helper.cs Просмотреть файл

@@ -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));
}
}
}

Загрузка…
Отмена
Сохранить