Class ExtensionMethods
General-purpose extension methods.
Inheritance
Inherited Members
Namespace: ExtendedXmlSerializer
Assembly: ExtendedXmlSerializer.dll
Syntax
public static class ExtensionMethods
Methods
Apply<T>(ICommand<T>, T)
Convenience method to invoke a command and return the parameter. This is useful for fluent-based configuration method calls.
Declaration
public static T Apply<T>(this ICommand<T> this, T parameter)
Parameters
ICommand<T>
this
The command to call. |
T
parameter
The parameter to pass to the command and return. |
Returns
T
The provided parameter. |
Type Parameters
T
The parameter type. |
Apply<T>(Action<T>, T)
Convenience method to invoke a method and return the parameter. This is useful for fluent-based configuration method calls.
Declaration
public static T Apply<T>(this Action<T> this, T parameter)
Parameters
System.Action<T>
this
The delegate to call. |
T
parameter
The parameter to pass to the delegate and return. |
Returns
T
The provided parameter. |
Type Parameters
T
The parameter type. |
Apply<T>(ICollection<T>, T)
Convenience method to add an element to a collection, and return the element. This is useful for fluent-based configuration method calls.
Declaration
public static T Apply<T>(this ICollection<T> this, T parameter)
Parameters
System.Collections.Generic.ICollection<T>
this
The collection to add an element to. |
T
parameter
The element to add. |
Returns
T
The element. |
Type Parameters
T
The element type. |
Apply<TKey, TValue>(IAssignable<TKey, TValue>, TKey, TValue)
Convenience method to pass values to an assignable command, and return the command. This is useful for fluent-based configuration method calls.
Declaration
public static IAssignable<TKey, TValue> Apply<TKey, TValue>(this IAssignable<TKey, TValue> this, TKey key, TValue value)
Parameters
IAssignable<TKey, TValue>
this
The assignable to command to invoke. |
TKey
key
The key to pass in. |
TValue
value
The value to pass in. |
Returns
IAssignable<TKey, TValue>
The assignable command. |
Type Parameters
TKey
The key type. |
TValue
The value type. |
AsValid<T>(Object, String)
Convenience method to cast instance to the requested type. If it cannot, an System.InvalidOperationException is thrown.
Declaration
public static T AsValid<T>(this object this, string message = null)
Parameters
System.Object
this
The instance to cast. |
System.String
message
The message to display if an exception is thrown. |
Returns
T
The casted, validated instance. |
Type Parameters
T
The requested type |
Only<T>(IEnumerable<T>)
Gets the only element if it exists, otherwise returns the type's default.
Declaration
public static T Only<T>(this IEnumerable<T> this)
Parameters
System.Collections.Generic.IEnumerable<T>
this
The set to query. |
Returns
T
The only element, if it exists. |
Type Parameters
T
The element type. |
Only<T>(ImmutableArray<T>)
Gets the only element if it exists, otherwise returns the type's default.
Declaration
public static T Only<T>(this ImmutableArray<T> this)
Parameters
System.Collections.Immutable.ImmutableArray<T>
this
The set to query. |
Returns
T
The only element, if it exists. |
Type Parameters
T
The element type. |
PropertyOrField(UnaryExpression, Type, String)
Convenience method that queries an expression to resolve a property or field expression.
Declaration
public static MemberExpression PropertyOrField(this UnaryExpression expression, Type type, string name)
Parameters
System.Linq.Expressions.UnaryExpression
expression
The expression to query. |
System.Type
type
The member containing type. |
System.String
name
The member name. |
Returns
System.Linq.Expressions.MemberExpression
The resolved member expression. |
Return<T, TOut>(T, TOut)
Convenience method used for fluent-type methods.
Declaration
public static TOut Return<T, TOut>(this T _, TOut result)
Parameters
T
_
Not used. |
TOut
result
The result. |
Returns
TOut
TOut. |
Type Parameters
T
The type of the calling instance. |
TOut
The result type. |
To<T>(Object)
Convenience method to case object to requested type. Easier for fluent expressions.
Declaration
public static T To<T>(this object this)
Parameters
System.Object
this
The object to cast. |
Returns
T
An instance of the request type if it can be cast. Otherwise, the type's default is returned. |
Type Parameters
T
The requested type. |