TypeConverters

Namespace: SnowBank.Runtime.Converters · class

Helper class for converting instances from one type to another

Methods

AsFunc

static Func<TInput, TOutput> AsFunc<TInput, TOutput>(ITypeConverter<TInput, TOutput> converter)

Wrap a Tye Converter into a corresponding Func<....>

  • converter — Instance that can convert from TInput to TOutput

Returns: Lambda function that, when called, invokes converter

Convert

static TOutput Convert<TInput, TOutput>(TInput value)

Convert a value of type TInput into type TOutput

  • value — Value to convert

Returns: Converted value

ConvertAll

static IEnumerable<TOutput> ConvertAll<TInput, TOutput>(ITypeConverter<TInput, TOutput> converter, IEnumerable<TInput> items)

Converts all the elements of a sequence

Returns: New sequence with all the converted elements

static List<TOutput> ConvertAll<TInput, TOutput>(ITypeConverter<TInput, TOutput> converter, List<TInput> items)

Converts all the elements of a list

Returns: New list with all the converted elements

static TOutput[] ConvertAll<TInput, TOutput>(ITypeConverter<TInput, TOutput> converter, TInput[] items)

Converts all the elements of an array

Returns: New array with all the converted elements

ConvertBoxed

static T ConvertBoxed<T>(object value)

Convert a boxed value into type T

  • value — Boxed value

Returns: Converted value, or an exception if there are no known conversions. The value null is converted into default(T) by convention

Create

static ITypeConverter<TInput, TOutput> Create<TInput, TOutput>(Func<TInput, TOutput> converter)

Helper method that wraps a lambda function into a converter

  • converter — Lambda that converts a value of type TInput into a value of type TOutput

Returns: Converters that wraps the lambda

CreateBoxedConverter

static Func<TInput, object> CreateBoxedConverter<TInput>(Type outputType)

Create a boxed converter from TInput to outputType

FromString

static TOutput FromString<TOutput>(string text)

GetConverter

static ITypeConverter<TInput, TOutput> GetConverter<TInput, TOutput>()

Returns a converter that converts TInputs into TOutputs

Returns: Valid converter for these types, or an exception if there are no known conversions

Register

static void Register<TInput, TOutput>(Func<TInput, TOutput> converter)

Registers a new type converter

  • converter — Lambda that converts a value of type TInput into a value of type TOutput

static void Register<TInput, TOutput>(ITypeConverter<TInput, TOutput> converter)

Registers a new type converter

  • converter — Instance that can convert values of type TInput into a values of type TOutput

ToString

static string ToString<TInput>(TInput value)

static string ToString(object value)

Unbox

static T Unbox<T>(object value)

Cast a boxed value (known to be of type T) into an unboxed value

  • value — Value that is known to be of type T, but is boxed into an object

Returns: Original value cast into its runtime type