Class Func
Provides extension methods for delegate Func<TResult> and predefined functions.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class Func
Methods
| Edit this page View SourceAsConverter<TInput, TOutput>(Func<TInput, TOutput>)
Converts Func<T, TResult> into Converter<TInput, TOutput>.
Declaration
public static Converter<TInput, TOutput> AsConverter<TInput, TOutput>(this Func<TInput, TOutput> function)
Parameters
Type | Name | Description |
---|---|---|
Func<TInput, TOutput> | function | The function to convert. |
Returns
Type | Description |
---|---|
Converter<TInput, TOutput> | A delegate of type Converter<TInput, TOutput> referencing the same method as original delegate. |
Type Parameters
Name | Description |
---|---|
TInput | Type of input argument. |
TOutput | Return type of the converter. |
AsPredicate<T>(Func<T, bool>)
Converts Func<T, TResult> into predicate.
Declaration
public static Predicate<T> AsPredicate<T>(this Func<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Func<T, bool> | predicate | A delegate to convert. |
Returns
Type | Description |
---|---|
Predicate<T> | A delegate of type Predicate<T> referencing the same method as original delegate. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
Constant<T>(T)
Constructs Func<TResult> returning the same instance each call.
Declaration
public static Func<T> Constant<T>(T obj)
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be returned from the delegate. |
Returns
Type | Description |
---|---|
Func<T> | The delegate returning |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be returned from the delegate. |
Identity<T>()
The converter which returns input argument without any modifications.
Declaration
public static Func<T, T> Identity<T>()
Returns
Type | Description |
---|---|
Func<T, T> | The identity function. |
Type Parameters
Name | Description |
---|---|
T | Type of input and output. |
Remarks
This method returns the same instance of predicate on every call.
Identity<T>(Action<T>)
Represents Action<T> as Func<T, TResult> which doesn't modify the input value.
Declaration
public static Func<T, T> Identity<T>(this Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to be converted. |
Returns
Type | Description |
---|---|
Func<T, T> | Func<T, TResult> that wraps |
Type Parameters
Name | Description |
---|---|
T | The type of the element. |
Identity<TInput, TOutput>()
The function which returns input argument without any modifications.
Declaration
public static Func<TInput, TOutput> Identity<TInput, TOutput>() where TInput : TOutput
Returns
Type | Description |
---|---|
Func<TInput, TOutput> | The identity function. |
Type Parameters
Name | Description |
---|---|
TInput | Type of input. |
TOutput | Type of output. |
Remarks
This method returns the same instance of predicate on every call.
IsNotNull<T>()
Returns predicate checking that input argument is not null.
Declaration
public static Func<T, bool> IsNotNull<T>() where T : class?
Returns
Type | Description |
---|---|
Func<T, bool> | The predicate instance. |
Type Parameters
Name | Description |
---|---|
T | Type of the predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
IsNull<T>()
Returns predicate implementing nullability check.
Declaration
public static Func<T, bool> IsNull<T>() where T : class?
Returns
Type | Description |
---|---|
Func<T, bool> | The predicate instance. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
IsTypeOf<T>()
Gets a predicate that can be used to check whether the specified object is of specific type.
Declaration
public static Func<object?, bool> IsTypeOf<T>()
Returns
Type | Description |
---|---|
Func<object, bool> | The predicate instance. |
Type Parameters
Name | Description |
---|---|
T | The target type. |
TryInvoke<TResult>(Func<TResult>)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<TResult>(this Func<TResult> function)
Parameters
Type | Name | Description |
---|---|---|
Func<TResult> | function | The function to invoke. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>, T1, T2, T3, T4, T5, T6, T7, T8, T9)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
T5 | arg5 | The fifth function argument. |
T6 | arg6 | The sixth function argument. |
T7 | arg7 | The seventh function argument. |
T8 | arg8 | The eighth function argument. |
T9 | arg9 | The ninth function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
T5 | The type of the fifth function argument. |
T6 | The type of the sixth function argument. |
T7 | The type of the seventh function argument. |
T8 | The type of the eighth function argument. |
T9 | The type of the ninth function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
T5 | arg5 | The fifth function argument. |
T6 | arg6 | The sixth function argument. |
T7 | arg7 | The seventh function argument. |
T8 | arg8 | The eighth function argument. |
T9 | arg9 | The ninth function argument. |
T10 | arg10 | The tenth function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
T5 | The type of the fifth function argument. |
T6 | The type of the sixth function argument. |
T7 | The type of the seventh function argument. |
T8 | The type of the eighth function argument. |
T9 | The type of the ninth function argument. |
T10 | The type of the tenth function argument. |
TResult | The result type. |
TryInvoke<T, TResult>(Func<T, TResult>, T)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T, TResult>(this Func<T, TResult> function, T arg)
Parameters
Type | Name | Description |
---|---|---|
Func<T, TResult> | function | The function to invoke. |
T | arg | The first function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T | The type of the first function argument. |
TResult | The result type. |
TryInvoke<T1, T2, TResult>(Func<T1, T2, TResult>, T1, T2)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, TResult>(this Func<T1, T2, TResult> function, T1 arg1, T2 arg2)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult>, T1, T2, T3)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, T2 arg2, T3 arg3)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult>, T1, T2, T3, T4)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, TResult>(this Func<T1, T2, T3, T4, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult>, T1, T2, T3, T4, T5)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, T5, TResult>(this Func<T1, T2, T3, T4, T5, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
T5 | arg5 | The fifth function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
T5 | The type of the fifth function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, T5, T6, TResult>(Func<T1, T2, T3, T4, T5, T6, TResult>, T1, T2, T3, T4, T5, T6)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, T5, T6, TResult>(this Func<T1, T2, T3, T4, T5, T6, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, T6, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
T5 | arg5 | The fifth function argument. |
T6 | arg6 | The sixth function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
T5 | The type of the fifth function argument. |
T6 | The type of the sixth function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, T5, T6, T7, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, TResult>, T1, T2, T3, T4, T5, T6, T7)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, T5, T6, T7, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, T6, T7, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
T5 | arg5 | The fifth function argument. |
T6 | arg6 | The sixth function argument. |
T7 | arg7 | The seventh function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
T5 | The type of the fifth function argument. |
T6 | The type of the sixth function argument. |
T7 | The type of the seventh function argument. |
TResult | The result type. |
TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>, T1, T2, T3, T4, T5, T6, T7, T8)
Invokes function without throwing the exception.
Declaration
public static Result<TResult> TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> | function | The function to invoke. |
T1 | arg1 | The first function argument. |
T2 | arg2 | The second function argument. |
T3 | arg3 | The third function argument. |
T4 | arg4 | The fourth function argument. |
T5 | arg5 | The fifth function argument. |
T6 | arg6 | The sixth function argument. |
T7 | arg7 | The seventh function argument. |
T8 | arg8 | The eighth function argument. |
Returns
Type | Description |
---|---|
Result<TResult> | The invocation result. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first function argument. |
T2 | The type of the second function argument. |
T3 | The type of the third function argument. |
T4 | The type of the fourth function argument. |
T5 | The type of the fifth function argument. |
T6 | The type of the sixth function argument. |
T7 | The type of the seventh function argument. |
T8 | The type of the eighth function argument. |
TResult | The result type. |