PeanutButter
Loading...
Searching...
No Matches
PeanutButter.DuckTyping.Extensions.ConversionExtensions Class Reference

Provides an extension method on object to attempt to convert to any other type supported by any existing (or located) converters. If you need a special conversion to happen then implement IConverter<T1, T2> to convert between T1 and T2. Common .net type conversion from strings is already supported (based on culture-invariant conversions, eg "1.23" -> 1.23M) More...

Static Public Member Functions

static bool TryConvertTo< T > (this object input, out T converted)
 Attempts to convert the object being operated on to the required type.
static bool TryConvertTo (this object input, Type desiredType, out object converted)
 Attempts to convert the object being operated on to the required type.

Detailed Description

Provides an extension method on object to attempt to convert to any other type supported by any existing (or located) converters. If you need a special conversion to happen then implement IConverter<T1, T2> to convert between T1 and T2. Common .net type conversion from strings is already supported (based on culture-invariant conversions, eg "1.23" -> 1.23M)

Member Function Documentation

◆ TryConvertTo()

bool PeanutButter.DuckTyping.Extensions.ConversionExtensions.TryConvertTo ( this object input,
Type desiredType,
out object converted )
static

Attempts to convert the object being operated on to the required type.

  • null always returns false
  • attempting to convert to the same type returns the original object
Parameters
input
desiredType
converted
Returns

◆ TryConvertTo< T >()

bool PeanutButter.DuckTyping.Extensions.ConversionExtensions.TryConvertTo< T > ( this object input,
out T converted )
static

Attempts to convert the object being operated on to the required type.

  • null always returns false
  • attempting to convert to the same type returns the original object
Parameters
input
converted
Template Parameters
T
Returns

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.DuckTyping/Extensions/ConversionExtensions.cs