Improve this Doc
View Source
Class Predef
Provides static methods to create instances of <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref>. Meant for
using as static import (C# 6 feature).
Inheritance
System.Object
Predef
Namespace:NiceTry
Assembly:NiceTry.dll
Syntax
Methods
|
Improve this Doc
View Source
Fail<T>(Exception)
Returns an new <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> wrapping the specified <em>err</em>.
Declaration
[NotNull]
public static Try<T> Fail<T>([NotNull] Exception err)
Parameters
Type |
Name |
Description |
System.Exception |
err |
|
Returns
Type Parameters
|
Improve this Doc
View Source
Ok<T>(T)
Returns a new <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref> wrapping the specified <em>value</em>.
Declaration
[NotNull]
public static Try<T> Ok<T>([CanBeNull] T value)
Parameters
Type |
Name |
Description |
T |
value |
|
Returns
Type Parameters
|
Improve this Doc
View Source
Try(Action)
Calls the specified <em>work</em> action and returns a <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> that represents the success or failure of that operation.
Declaration
[NotNull]
public static Try<Unit> Try([NotNull] Action work)
Parameters
Type |
Name |
Description |
System.Action |
work |
|
Returns
Type |
Description |
Try<TheVoid.Unit> |
|
|
Improve this Doc
View Source
Try<T>(Func<T>)
Calls the specified <em>work</em> function and returns a <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> that represents the success or failure of that operation.
Declaration
[NotNull]
public static Try<T> Try<T>([NotNull] Func<T> work)
Parameters
Type |
Name |
Description |
System.Func<T> |
work |
|
Returns
Type Parameters
|
Improve this Doc
View Source
Try<T>(Func<Try<T>>)
Calls the specified <em>work</em> function and returns the produced <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> that represents the success or failure of that operation.
Declaration
[NotNull]
public static Try<T> Try<T>([NotNull] Func<Try<T>> work)
Parameters
Type |
Name |
Description |
System.Func<Try<T>> |
work |
|
Returns
Type Parameters
|
Improve this Doc
View Source
Using<Disposable>(Func<Disposable>, Action<Disposable>)
Creates, uses and properly disposes a <xref href="System.IDisposable" data-throw-if-not-resolved="false"></xref> specified by the
<em>createDisposable</em> and <em>useDisposable</em> functions
and returns a <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> that represents the success or failure of that operation.
Declaration
[NotNull]
public static Try<Unit> Using<Disposable>([NotNull] Func<Disposable> createDisposable, [NotNull] Action<Disposable> useDisposable)where Disposable : IDisposable
Parameters
Type |
Name |
Description |
System.Func<Disposable> |
createDisposable |
|
System.Action<Disposable> |
useDisposable |
|
Returns
Type |
Description |
Try<TheVoid.Unit> |
|
Type Parameters
Name |
Description |
Disposable |
|
|
Improve this Doc
View Source
Using<Disposable, T>(Func<Disposable>, Func<Disposable, T>)
Creates, uses and properly disposes a <xref href="System.IDisposable" data-throw-if-not-resolved="false"></xref> specified by the
<em>createDisposable</em> and <em>useDisposable</em> functions
and returns a <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> that represents the success or failure of that operation.
Declaration
[NotNull]
public static Try<T> Using<Disposable, T>([NotNull] Func<Disposable> createDisposable, [NotNull] Func<Disposable, T> useDisposable)where Disposable : IDisposable
Parameters
Type |
Name |
Description |
System.Func<Disposable> |
createDisposable |
Create disposable.
|
System.Func<Disposable, T> |
useDisposable |
Use disposable.
|
Returns
Type Parameters
Name |
Description |
Disposable |
The 1st type parameter. |
T |
The 2nd type parameter. |
|
Improve this Doc
View Source
Using<Disposable, T>(Func<Disposable>, Func<Disposable, Try<T>>)
Creates, uses and properly disposes a <xref href="System.IDisposable" data-throw-if-not-resolved="false"></xref> specified by the
<em>createDisposable</em> and <em>useDisposable</em> functions
and returns a <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> that represents the success or failure of that operation.
Declaration
[NotNull]
public static Try<T> Using<Disposable, T>([NotNull] Func<Disposable> createDisposable, [NotNull] Func<Disposable, Try<T>> useDisposable)where Disposable : IDisposable
Parameters
Type |
Name |
Description |
System.Func<Disposable> |
createDisposable |
Create disposable.
|
System.Func<Disposable, Try<T>> |
useDisposable |
Use disposable.
|
Returns
Type Parameters
Name |
Description |
Disposable |
The 1st type parameter. |
T |
The 2nd type parameter. |