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 ba988f7f28
Update TypeExtensions.cs
Added xml comment on IsCastableFrom
2022-09-12 18:43:28 -06:00

17 lines
567 B
C#

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