TypeHelpers update

Add check for numerics types
pull/1/head
unknown 3 years ago
parent 0060b766b5
commit 8947bb5c7d

@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using Xunit; using Xunit;
using ZeroLevel.Services.Serialization; using ZeroLevel.Services.Serialization;
using ZeroLevel.Services.Trees; using ZeroLevel.Services.Trees;

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using Xunit; using Xunit;
using ZeroLevel.Services.FileSystem; using ZeroLevel.Services.FileSystem;

@ -586,7 +586,7 @@ namespace ZeroLevel.Services.Config
if (string.IsNullOrWhiteSpace(line)) yield return StringToTypeConverter.TryConvert(line, elementType); if (string.IsNullOrWhiteSpace(line)) yield return StringToTypeConverter.TryConvert(line, elementType);
foreach (var part in line.Split(',')) foreach (var part in line.Split(','))
{ {
if (part.IndexOf('-') >= 0) if (TypeHelpers.IsNumericType(elementType) && part.IndexOf('-') >= 0)
{ {
var lr = part.Split('-'); var lr = part.Split('-');
if (lr.Length == 2) if (lr.Length == 2)

@ -28,6 +28,27 @@ namespace ZeroLevel.Services.Reflection
return IsAssignableToGenericType(baseType, genericType); return IsAssignableToGenericType(baseType, genericType);
} }
public static bool IsNumericType(Type type)
{
switch (Type.GetTypeCode(type))
{
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
default:
return false;
}
}
public static bool IsEnum(Type type) public static bool IsEnum(Type type)
{ {
return type.Return(t => t.IsEnum, false); return type.Return(t => t.IsEnum, false);

@ -44,7 +44,7 @@ namespace ZeroLevel.Services.Shedulling
{ {
try try
{ {
result.Callback(result.Key); result.Callback.Invoke(result.Key);
} }
catch (Exception ex) catch (Exception ex)
{ {

Loading…
Cancel
Save

Powered by TurnKey Linux.