C# Класс Nvelope.TypeExtensions

Some helpers for casting objects using built-in CLR casting operators
Показать файл Открыть проект

Открытые методы

Метод Описание
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.

Описание методов

DynamicCast() публичный статический Метод

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
Результат object

GetCastMethod() публичный статический Метод

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
Результат System.Reflection.MethodInfo

GetLoadableTypes() публичный статический Метод

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
Результат IEnumerable