Provides a set of extension methods to enable duck-typing.
More...
|
static bool | CanDuckAs< T > (this object src) |
| Tests whether or not a given object can be accurately duck-typed to the requested interface T. Accurate duck-typing requires exact matching of property names and types as well as method names and signatures.
|
static bool | CanFuzzyDuckAs< T > (this object src) |
| Tests whether or not a given object can be approximately duck-typed to the requested interface T. Fuzzy ducking will attempt to bridge when there are case mismatches in property and method names as well as attempting auto-conversion between underlying and exposed types (eg: a Guid property could be backed by an underlying string property) and will attempt parameter re-ordering when ducking methods, if required and possible.
|
static T | DuckAs< T > (this object src) |
| Attempts to accurately duck-type an object to an interface.
|
static T | DuckAs< T > (this object src, bool throwOnError) |
| Attempts to accurately duck-type an object to an interface.
|
static object | FuzzyDuckAs (this object src, Type toType) |
| Attempts to approximately duck-type an object to a a provided interface type.
|
static object | FuzzyDuckAs (this object src, Type toType, bool throwOnError) |
| Attempts to approximately duck-type an object to a a provided interface type.
|
static object | DuckAs (this object src, Type toType) |
| Attempts to accurately duck-type an object to a a provided interface type.
|
static object | DuckAs (this object src, Type toType, bool throwOnError) |
| Attempts to accurately duck-type an object to a a provided interface type.
|
static T | FuzzyDuckAs< T > (this object src) |
| Attempts to approximately duck-type an object to a a provided interface type.
|
static T | FuzzyDuckAs< T > (this object src, bool throwOnError) |
| Attempts to approximately duck-type an object to a a provided interface type.
|
Provides a set of extension methods to enable duck-typing.
◆ CanDuckAs< T >()
bool PeanutButter.DuckTyping.Extensions.DuckTypingObjectExtensions.CanDuckAs< T > |
( |
this object | src | ) |
|
|
static |
Tests whether or not a given object can be accurately duck-typed to the requested interface T. Accurate duck-typing requires exact matching of property names and types as well as method names and signatures.
- Parameters
-
- Template Parameters
-
T | Desired interface to duck to |
- Returns
- True when the object can be accurately duck-typed; false otherwise. A false result here may not necessarily mean a false result from CanFuzzyDuckAs
◆ CanFuzzyDuckAs< T >()
bool PeanutButter.DuckTyping.Extensions.DuckTypingObjectExtensions.CanFuzzyDuckAs< T > |
( |
this object | src | ) |
|
|
static |
Tests whether or not a given object can be approximately duck-typed to the requested interface T. Fuzzy ducking will attempt to bridge when there are case mismatches in property and method names as well as attempting auto-conversion between underlying and exposed types (eg: a Guid property could be backed by an underlying string property) and will attempt parameter re-ordering when ducking methods, if required and possible.
- Parameters
-
- Template Parameters
-
T | Desired interface to duck to |
- Returns
- True when the object can be approximately duck-typed; false otherwise
◆ DuckAs() [1/2]
object PeanutButter.DuckTyping.Extensions.DuckTypingObjectExtensions.DuckAs |
( |
this object | src, |
|
|
Type | toType ) |
|
static |
Attempts to accurately duck-type an object to a a provided interface type.
- Parameters
-
src | Object to duck-type |
toType | Type of interface required |
- Returns
- If accurate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null.
◆ DuckAs() [2/2]
object PeanutButter.DuckTyping.Extensions.DuckTypingObjectExtensions.DuckAs |
( |
this object | src, |
|
|
Type | toType, |
|
|
bool | throwOnError ) |
|
static |
Attempts to accurately duck-type an object to a a provided interface type.
- Parameters
-
src | Object to duck-type |
toType | Type of interface required |
throwOnError | Flag to determine whether failure to duck should throw an exception |
- Returns
- If accurate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null when throwOnError is false or throws an UnDuckableException when throwOnError is true.
◆ DuckAs< T >() [1/2]
Attempts to accurately duck-type an object to an interface.
- Parameters
-
- Template Parameters
-
- Returns
- If accurate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null.
◆ DuckAs< T >() [2/2]
Attempts to accurately duck-type an object to an interface.
- Parameters
-
src | Object to duck-type |
throwOnError | Flag to allow throwing and exception when ducking cannot be achieved. The thrown exception contains information about what caused ducking to fail. |
- Template Parameters
-
- Returns
- If accurate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null when throwOnError is false or throws an UnDuckableException if throwOnError is true.
◆ FuzzyDuckAs() [1/2]
object PeanutButter.DuckTyping.Extensions.DuckTypingObjectExtensions.FuzzyDuckAs |
( |
this object | src, |
|
|
Type | toType ) |
|
static |
Attempts to approximately duck-type an object to a a provided interface type.
- Parameters
-
src | Object to duck-type |
toType | Type of interface required |
- Returns
- If approximate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null.
◆ FuzzyDuckAs() [2/2]
object PeanutButter.DuckTyping.Extensions.DuckTypingObjectExtensions.FuzzyDuckAs |
( |
this object | src, |
|
|
Type | toType, |
|
|
bool | throwOnError ) |
|
static |
Attempts to approximately duck-type an object to a a provided interface type.
- Parameters
-
src | Object to duck-type |
toType | Type of interface required |
throwOnError | Flag to determine whether failure to duck should throw an exception |
- Returns
- If approximate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null when throwOnError is false or throws an UnDuckableException when throwOnError is true.
◆ FuzzyDuckAs< T >() [1/2]
Attempts to approximately duck-type an object to a a provided interface type.
- Parameters
-
<paramtype name="T">Type of interface required</paramtype>
- Returns
- If approximate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null.
◆ FuzzyDuckAs< T >() [2/2]
Attempts to approximately duck-type an object to a a provided interface type.
- Parameters
-
src | Object to duck-type |
throwOnError | Flag to determine whether failure to duck should throw an exception |
<paramtype name="T">Type of interface required</paramtype>
- Returns
- If approximate ducking is possible, this method returns a new object which wraps around the input object, exposing the properties and methods of the requested interface whilst calling through to the underlying object. If ducking cannot be achieved, this method silently returns null when throwOnError is false or throws an UnDuckableException when throwOnError is true.
The documentation for this class was generated from the following file:
- source/Utils/PeanutButter.DuckTyping/Extensions/DuckTypingObjectExtensions.cs