Show / Hide Table of Contents

Class Patterns

Provides a generic way to support different types of design patterns and practices with small utility methods.

Inheritance
Object
Patterns
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public sealed class Patterns

Properties

| Improve this Doc View Source

Use

Gets the singleton instance of the Patterns functionality allowing for extensions methods like: Patterns.Use.SomeIngeniousMethod().

Declaration
public static Patterns Use { get; }
Property Value
Type Description
Patterns

The singleton instance of the Patterns functionality.

Methods

| Improve this Doc View Source

Configure<TOptions>(Action<TOptions>, Action<TOptions>, Action<TOptions>)

Returns the default parameter-less constructed instance of TOptions configured with setup delegate.

Declaration
public static TOptions Configure<TOptions>(Action<TOptions> setup, Action<TOptions> initializer = null, Action<TOptions> validator = null)

    where TOptions : class, IParameterObject, new()
Parameters
Type Name Description
Action<TOptions> setup

The delegate that will configure the public read-write properties of TOptions.

Action<TOptions> initializer

The optional delegate that will initialize the default parameter-less constructed instance of TOptions. Should only be used with third party libraries or for validation purposes.

Action<TOptions> validator

The optional delegate that will validate the TOptions configured by the setup delegate.

Returns
Type Description
TOptions

A default constructed instance of TOptions initialized with the options of setup.

Type Parameters
Name Description
TOptions

The type of the configuration options class having a default constructor.

Remarks

Often referred to as part the Options pattern: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options

| Improve this Doc View Source

ConfigureExchange<TSource, TResult>(Action<TSource>, Action<TSource, TResult>)

Returns the delegate that will configure the public read-write properties of TResult.

Declaration
public static Action<TResult> ConfigureExchange<TSource, TResult>(Action<TSource> setup, Action<TSource, TResult> initializer = null)

    where TSource : class, IParameterObject, new()

    where TResult : class, new()
Parameters
Type Name Description
Action<TSource> setup

The delegate that will configure the public read-write properties of TSource.

Action<TSource, TResult> initializer

The delegate that will exchange the parameter of setup from TSource to TResult.

Returns
Type Description
Action<TResult>

An Action<T> otherwise equivalent to setup.

Type Parameters
Name Description
TSource

The type of the configuration options class having a default constructor.

TResult

The type of the configuration options class having a default constructor.

| Improve this Doc View Source

ConfigureRevert<TOptions>(TOptions)

Returns the delegate that will configure the public read-write properties of TOptions.

Declaration
public static Action<TOptions> ConfigureRevert<TOptions>(TOptions options)

    where TOptions : class, new()
Parameters
Type Name Description
TOptions options

An instance of the configured options.

Returns
Type Description
Action<TOptions>

An Action<T> otherwise equivalent to options.

Type Parameters
Name Description
TOptions

The type of the configuration options having a default constructor.

Exceptions
Type Condition
ArgumentNullException

options cannot be null.

| Improve this Doc View Source

ConfigureRevertExchange<TSource, TResult>(TSource, Action<TSource, TResult>)

Returns a delegate that will be initialized by initializer with the values from options.

Declaration
public static Action<TResult> ConfigureRevertExchange<TSource, TResult>(TSource options, Action<TSource, TResult> initializer = null)

    where TSource : class, IParameterObject, new()

    where TResult : class, new()
Parameters
Type Name Description
TSource options

The configured options to apply an instance of TResult.

Action<TSource, TResult> initializer

The delegate that will initialize a default instance of TResult with the values from options.

Returns
Type Description
Action<TResult>

An Action<T> with the values from options.

Type Parameters
Name Description
TSource

The type of the configuration options having a default constructor.

TResult

The type of the configuration options having a default constructor.

Exceptions
Type Condition
ArgumentNullException

options cannot be null -or- initializer cannot be null.

| Improve this Doc View Source

CreateInstance<T>(Action<T>)

Provides a generic way to initialize the default, parameterless constructed instance of T.

Declaration
public static T CreateInstance<T>(Action<T> factory)

    where T : class, new()
Parameters
Type Name Description
Action<T> factory

The delegate that will initialize the public write properties of T.

Returns
Type Description
T

A default constructed instance of T initialized with factory.

Type Parameters
Name Description
T

The type of the class having a default constructor.

| Improve this Doc View Source

InvokeOrDefault<TResult>(Func<TResult>, TResult)

Returns an object of TResult, or a default value if the specified method throws an exception.

Declaration
public static TResult InvokeOrDefault<TResult>(Func<TResult> method, TResult fallbackResult = null)
Parameters
Type Name Description
Func<TResult> method

The function delegate that will return an instance of TResult.

TResult fallbackResult

The value to return when the specified method throws an exception. Default is default of TResult.

Returns
Type Description
TResult

An object of TResult when the specified method can be invoked without an exception; otherwise fallbackResult is returned.

Type Parameters
Name Description
TResult

The type of the return value of the method.

| Improve this Doc View Source

SafeInvoke<TResult>(Func<TResult>, Func<TResult, TResult>, Action<Exception>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static TResult SafeInvoke<TResult>(Func<TResult> initializer, Func<TResult, TResult> tester, Action<Exception> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, TResult> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

Action<Exception> catcher

The delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
TResult

The return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvoke<T, TResult>(Func<TResult>, Func<TResult, T, TResult>, T, Action<Exception, T>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static TResult SafeInvoke<T, TResult>(Func<TResult> initializer, Func<TResult, T, TResult> tester, T arg, Action<Exception, T> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T, TResult> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T arg

The parameter of the function delegate tester and delegate catcher.

Action<Exception, T> catcher

The delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
TResult

The return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T

The type of the parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvoke<T1, T2, TResult>(Func<TResult>, Func<TResult, T1, T2, TResult>, T1, T2, Action<Exception, T1, T2>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static TResult SafeInvoke<T1, T2, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, TResult> tester, T1 arg1, T2 arg2, Action<Exception, T1, T2> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, TResult> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

Action<Exception, T1, T2> catcher

The delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
TResult

The return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvoke<T1, T2, T3, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, TResult>, T1, T2, T3, Action<Exception, T1, T2, T3>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static TResult SafeInvoke<T1, T2, T3, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, TResult> tester, T1 arg1, T2 arg2, T3 arg3, Action<Exception, T1, T2, T3> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, T3, TResult> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

T3 arg3

The third parameter of the function delegate tester and delegate catcher.

Action<Exception, T1, T2, T3> catcher

The delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
TResult

The return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvoke<T1, T2, T3, T4, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, TResult>, T1, T2, T3, T4, Action<Exception, T1, T2, T3, T4>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static TResult SafeInvoke<T1, T2, T3, T4, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, TResult> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<Exception, T1, T2, T3, T4> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, T3, T4, TResult> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

T3 arg3

The third parameter of the function delegate tester and delegate catcher.

T4 arg4

The fourth parameter of the function delegate tester and delegate catcher.

Action<Exception, T1, T2, T3, T4> catcher

The delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
TResult

The return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

T4

The type of the fourth parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvoke<T1, T2, T3, T4, T5, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, T5, TResult>, T1, T2, T3, T4, T5, Action<Exception, T1, T2, T3, T4, T5>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static TResult SafeInvoke<T1, T2, T3, T4, T5, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, T5, TResult> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<Exception, T1, T2, T3, T4, T5> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, T3, T4, T5, TResult> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

T3 arg3

The third parameter of the function delegate tester and delegate catcher.

T4 arg4

The fourth parameter of the function delegate tester and delegate catcher.

T5 arg5

The fifth parameter of the function delegate tester and delegate catcher.

Action<Exception, T1, T2, T3, T4, T5> catcher

The delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
TResult

The return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

T4

The type of the fourth parameter of the function delegate tester and delegate catcher.

T5

The type of the fifth parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvokeAsync<TResult>(Func<TResult>, Func<TResult, CancellationToken, Task<TResult>>, CancellationToken, Func<Exception, CancellationToken, Task>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static Task<TResult> SafeInvokeAsync<TResult>(Func<TResult> initializer, Func<TResult, CancellationToken, Task<TResult>> tester, CancellationToken ct = default(CancellationToken), Func<Exception, CancellationToken, Task> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, CancellationToken, Task<TResult>> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

CancellationToken ct

The token to monitor for cancellation requests. The default value is None.

Func<Exception, CancellationToken, Task> catcher

The function delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvokeAsync<T, TResult>(Func<TResult>, Func<TResult, T, CancellationToken, Task<TResult>>, T, CancellationToken, Func<Exception, T, CancellationToken, Task>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static Task<TResult> SafeInvokeAsync<T, TResult>(Func<TResult> initializer, Func<TResult, T, CancellationToken, Task<TResult>> tester, T arg, CancellationToken ct = default(CancellationToken), Func<Exception, T, CancellationToken, Task> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T, CancellationToken, Task<TResult>> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T arg

The parameter of the function delegate tester and delegate catcher.

CancellationToken ct

The token to monitor for cancellation requests. The default value is None.

Func<Exception, T, CancellationToken, Task> catcher

The function delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T

The type of the parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvokeAsync<T1, T2, TResult>(Func<TResult>, Func<TResult, T1, T2, CancellationToken, Task<TResult>>, T1, T2, CancellationToken, Func<Exception, T1, T2, CancellationToken, Task>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static Task<TResult> SafeInvokeAsync<T1, T2, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, CancellationToken ct = default(CancellationToken), Func<Exception, T1, T2, CancellationToken, Task> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, CancellationToken, Task<TResult>> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

CancellationToken ct

The token to monitor for cancellation requests. The default value is None.

Func<Exception, T1, T2, CancellationToken, Task> catcher

The function delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvokeAsync<T1, T2, T3, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>>, T1, T2, T3, CancellationToken, Func<Exception, T1, T2, T3, CancellationToken, Task>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static Task<TResult> SafeInvokeAsync<T1, T2, T3, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, CancellationToken ct = default(CancellationToken), Func<Exception, T1, T2, T3, CancellationToken, Task> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

T3 arg3

The third parameter of the function delegate tester and delegate catcher.

CancellationToken ct

The token to monitor for cancellation requests. The default value is None.

Func<Exception, T1, T2, T3, CancellationToken, Task> catcher

The function delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvokeAsync<T1, T2, T3, T4, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>>, T1, T2, T3, T4, CancellationToken, Func<Exception, T1, T2, T3, T4, CancellationToken, Task>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static Task<TResult> SafeInvokeAsync<T1, T2, T3, T4, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken ct = default(CancellationToken), Func<Exception, T1, T2, T3, T4, CancellationToken, Task> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

T3 arg3

The third parameter of the function delegate tester and delegate catcher.

T4 arg4

The fourth parameter of the function delegate tester and delegate catcher.

CancellationToken ct

The token to monitor for cancellation requests. The default value is None.

Func<Exception, T1, T2, T3, T4, CancellationToken, Task> catcher

The function delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

T4

The type of the fourth parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

SafeInvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>, T1, T2, T3, T4, T5, CancellationToken, Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task>)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

Declaration
public static Task<TResult> SafeInvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken ct = default(CancellationToken), Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task> catcher = null)

    where TResult : class, IDisposable
Parameters
Type Name Description
Func<TResult> initializer

The function delegate that initializes an object implementing the IDisposable interface.

Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>> tester

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

T1 arg1

The first parameter of the function delegate tester and delegate catcher.

T2 arg2

The second parameter of the function delegate tester and delegate catcher.

T3 arg3

The third parameter of the function delegate tester and delegate catcher.

T4 arg4

The fourth parameter of the function delegate tester and delegate catcher.

T5 arg5

The fifth parameter of the function delegate tester and delegate catcher.

CancellationToken ct

The token to monitor for cancellation requests. The default value is None.

Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task> catcher

The function delegate that will handle any exceptions might thrown by tester.

Returns
Type Description
Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters
Name Description
T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

T4

The type of the fourth parameter of the function delegate tester and delegate catcher.

T5

The type of the fifth parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

| Improve this Doc View Source

TryInvoke(Action)

Returns a value that indicates whether the specified method can be invoked without an exception.

Declaration
public static bool TryInvoke(Action method)
Parameters
Type Name Description
Action method

The delegate that to invoke.

Returns
Type Description
Boolean

true if method was called without raising an exception; otherwise false.

Remarks

Actually an anti-pattern in regards to swallowing exception. That said, there are situations where this is a perfectly valid approach.

| Improve this Doc View Source

TryInvoke<TResult>(Func<TResult>, out TResult)

Returns a value that indicates whether the specified method can be invoked without an exception.

Declaration
public static bool TryInvoke<TResult>(Func<TResult> method, out TResult result)
Parameters
Type Name Description
Func<TResult> method

The function delegate that will resolve result.

TResult result

When this method returns, contains the value returned from method; otherwise the default value for the type of the result parameter if an exception is thrown.

Returns
Type Description
Boolean

true if an instance of TResult has been created; otherwise false.

Type Parameters
Name Description
TResult

The type of the return value of the method.

Remarks

Often referred to as the Try-Parse pattern: https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/exceptions-and-performance

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright 2008-2022 Geekle. All rights reserved. Code with passion and love; deploy with confidence. 👨‍💻️🔥❤️🚀😎
Generated by DocFX