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:
parent
7473083b84
commit
5e3c5c0012
15
Scripts/TypeExtensions.cs
Normal file
15
Scripts/TypeExtensions.cs
Normal 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" );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user