1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00
xNode/Scripts/TypeExtensions.cs
Raistlin Wolfe 4acfc40adc
Update TypeExtensions.cs
Fixed Copy/Paste error missing using directive.
2022-09-16 12:19:19 -06:00

18 lines
581 B
C#

using System;
using System.Linq;
using System.Reflection;
public static class TypeExtensions
{
/// <summary> Determines whether an instance of a specified type can be assigned to a variable of the current type. </summary>
public static bool IsCastableFrom(this Type to, Type from)
{
if ( to.IsAssignableFrom ( from ) )
return true;
return from.GetMethods ( BindingFlags.Public | BindingFlags.Static ).Any ( m =>
{
return m.ReturnType == to && ( m.Name == "op_Implicit" || m.Name == "op_Explicit" );
} );
}
}