C# Class Nvelope.TypeExtensions

Some helpers for casting objects using built-in CLR casting operators
Show file Open project: TrinityWestern/Nvelope

Public Methods

Method Description
DynamicCast ( this targetType, object value ) : object

Cast an object from one type to the other using .Net conversion

There's a similar ConvertTo method in this library that is much more complicated and doesn't allow for user defined conversions

GetCastMethod ( Type from, Type to ) : MethodInfo

Gets the most appropriate cast method from one type to another

GetLoadableTypes ( this assembly ) : IEnumerable

Thank you Jon Skeet. http://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes Calling GetTypes() on an assembly that inherits from a non-referenced assembly will throw exceptions. This extension method will only get the types from the assembly that we actually can load.

Method Details

DynamicCast() public static method

Cast an object from one type to the other using .Net conversion
There's a similar ConvertTo method in this library that is much more complicated and doesn't allow for user defined conversions
Thrown if conversion fails
public static DynamicCast ( this targetType, object value ) : object
targetType this
value object
return object

GetCastMethod() public static method

Gets the most appropriate cast method from one type to another
public static GetCastMethod ( Type from, Type to ) : MethodInfo
from System.Type Type of initial object
to System.Type Type of casted object
return System.Reflection.MethodInfo

GetLoadableTypes() public static method

Thank you Jon Skeet. http://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes Calling GetTypes() on an assembly that inherits from a non-referenced assembly will throw exceptions. This extension method will only get the types from the assembly that we actually can load.
public static GetLoadableTypes ( this assembly ) : IEnumerable
assembly this
return IEnumerable