1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00

Create TypeExtensions.cs

Provided Implementation for IsCastableFrom
This commit is contained in:
Raistlin Wolfe 2022-09-12 18:36:45 -06:00 committed by GitHub
parent 7473083b84
commit 5e3c5c0012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

15
Scripts/TypeExtensions.cs Normal file
View File

@ -0,0 +1,15 @@
using System.Linq;
using System.Reflection;
public static class TypeExtensions
{
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" );
} );
}
}