Show / Hide Table of Contents

Class StaticFunctions

This class is intended to be use static'd and includes generic utility and readability functions

Inheritance
System.Object
StaticFunctions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Piksel.Helpers
Assembly: cs.temp.dll.dll
Syntax
public static class StaticFunctions
Examples

using static Piksel.Helpers.StaticFunctions;

Methods

Attempt<TResult>(Func<TResult>, String)

Execute tryFunc in a try-catch clause returning it's result. If it fails, throw new with set to failureMessage and set to the exception that was threwn by tryFunc.

Declaration
public static TResult Attempt<TResult>(Func<TResult> tryFunc, string failureMessage)
Parameters
Type Name Description
Func<TResult> tryFunc

The function to execute inside the clause

System.String failureMessage

The message that the resulting Exception will contain upon failure

Returns
Type Description
TResult

Instance of TResult if no exception was thrown

Type Parameters
Name Description
TResult

Type of return value, can usually be inferred from tryFunc

Examples

var something = Attempt(() => foo.GetSomethingThatMayFail(), "Failed to get Something from foo");

TryOrThrow(Action, String)

Execute tryFunc in a try-catch clause. If it fails, throw new with set to failureMessage and set to the exception that was thrown by tryFunc.

Declaration
public static void TryOrThrow(Action tryFunc, string failureMessage)
Parameters
Type Name Description
Action tryFunc

The function to execute inside the clause

System.String failureMessage

The message that the resulting Exception will contain upon failure

Examples

TryOrThrow(() => foo.DoSomethingThatMayFail(), "Failed to do Something using foo");

Back to top Generated by DocFX