Browse Source

Replace TypeInfo with Type.

pull/3476/head
Dariusz Komosinski 7 years ago
parent
commit
d7b07dec02
  1. 4
      src/Avalonia.Base/AvaloniaProperty.cs
  2. 32
      src/Avalonia.Base/Utilities/TypeUtilities.cs

4
src/Avalonia.Base/AvaloniaProperty.cs

@ -3,9 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Reactive.Subjects; using System.Reactive.Subjects;
using System.Reflection;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Utilities; using Avalonia.Utilities;
@ -602,7 +600,7 @@ namespace Avalonia
return result; return result;
} }
currentType = currentType.GetTypeInfo().BaseType; currentType = currentType.BaseType;
} }
_metadataCache[type] = _defaultMetadata; _metadataCache[type] = _defaultMetadata;

32
src/Avalonia.Base/Utilities/TypeUtilities.cs

@ -92,8 +92,7 @@ namespace Avalonia.Utilities
/// <returns>True if the type accepts null values; otherwise false.</returns> /// <returns>True if the type accepts null values; otherwise false.</returns>
public static bool AcceptsNull(Type type) public static bool AcceptsNull(Type type)
{ {
var t = type.GetTypeInfo(); return !type.IsValueType || IsNullableType(type);
return !t.IsValueType || (t.IsGenericType && (t.GetGenericTypeDefinition() == typeof(Nullable<>)));
} }
/// <summary> /// <summary>
@ -119,10 +118,8 @@ namespace Avalonia.Utilities
} }
var from = value.GetType(); var from = value.GetType();
var fromTypeInfo = from.GetTypeInfo();
var toTypeInfo = to.GetTypeInfo();
if (toTypeInfo.IsAssignableFrom(fromTypeInfo)) if (to.IsAssignableFrom(from))
{ {
result = value; result = value;
return true; return true;
@ -134,7 +131,7 @@ namespace Avalonia.Utilities
return true; return true;
} }
if (toTypeInfo.IsEnum && from == typeof(string)) if (to.IsEnum && from == typeof(string))
{ {
if (Enum.IsDefined(to, (string)value)) if (Enum.IsDefined(to, (string)value))
{ {
@ -143,7 +140,7 @@ namespace Avalonia.Utilities
} }
} }
if (!fromTypeInfo.IsEnum && toTypeInfo.IsEnum) if (!from.IsEnum && to.IsEnum)
{ {
result = null; result = null;
@ -154,7 +151,7 @@ namespace Avalonia.Utilities
} }
} }
if (fromTypeInfo.IsEnum && IsNumeric(to)) if (from.IsEnum && IsNumeric(to))
{ {
try try
{ {
@ -223,10 +220,8 @@ namespace Avalonia.Utilities
} }
var from = value.GetType(); var from = value.GetType();
var fromTypeInfo = from.GetTypeInfo();
var toTypeInfo = to.GetTypeInfo();
if (toTypeInfo.IsAssignableFrom(fromTypeInfo)) if (to.IsAssignableFrom(from))
{ {
result = value; result = value;
return true; return true;
@ -307,9 +302,7 @@ namespace Avalonia.Utilities
/// <returns>The default value.</returns> /// <returns>The default value.</returns>
public static object Default(Type type) public static object Default(Type type)
{ {
var typeInfo = type.GetTypeInfo(); if (type.IsValueType)
if (typeInfo.IsValueType)
{ {
return Activator.CreateInstance(type); return Activator.CreateInstance(type);
} }
@ -335,9 +328,11 @@ namespace Avalonia.Utilities
return false; return false;
} }
if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) Type underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType != null)
{ {
return IsNumeric(Nullable.GetUnderlyingType(type)); return IsNumeric(underlyingType);
} }
else else
{ {
@ -352,6 +347,11 @@ namespace Avalonia.Utilities
Explicit = 2 Explicit = 2
} }
private static bool IsNullableType(Type type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
}
private static MethodInfo FindTypeConversionOperatorMethod(Type fromType, Type toType, OperatorType operatorType) private static MethodInfo FindTypeConversionOperatorMethod(Type fromType, Type toType, OperatorType operatorType)
{ {
const string implicitName = "op_Implicit"; const string implicitName = "op_Implicit";

Loading…
Cancel
Save