diff --git a/Scripts/TypeExtensions.cs b/Scripts/TypeExtensions.cs new file mode 100644 index 0000000..5f79664 --- /dev/null +++ b/Scripts/TypeExtensions.cs @@ -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" ); + } ); + } +}