Show / Hide Table of Contents
Improve this Doc View Source

Class Try

Provides factory methods to create instances of <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref>. 
Inheritance
System.Object
Try
Namespace:NiceTry
Assembly:NiceTry.dll
Syntax
public class Try

Methods

| Improve this Doc View Source

AllOrFailure<T>(Try<T>[])

Returns a single <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref> containing all elements if all
<xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> in the specified <em>candidates</em> represent
success, or the first <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> otherwise.
Declaration
[NotNull]
public static Try<IEnumerable<T>> AllOrFailure<T>([NotNull] params Try<T>[] candidates)
Parameters
Type Name Description
Try<T>[] candidates
Returns
Type Description
Try<System.Collections.Generic.IEnumerable<T>>
Type Parameters
Name Description
T
| Improve this Doc View Source

AllOrFailure<T>(IEnumerable<Try<T>>)

Returns a single <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref> containing either the values of
all elements of the specified <em>candidates</em> if all elements
represent success, or the first <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> otherwise.
Declaration
[NotNull]
public static Try<IEnumerable<T>> AllOrFailure<T>([NotNull] IEnumerable<Try<T>> candidates)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Try<T>> candidates
Returns
Type Description
Try<System.Collections.Generic.IEnumerable<T>>
Type Parameters
Name Description
T
| Improve this Doc View Source

Failure<T>(Exception)

Wraps the specified <em>error</em> in a <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref>. 
Declaration
[NotNull]
public static Try<T> Failure<T>([NotNull] Exception error)
Parameters
Type Name Description
System.Exception error
Returns
Type Description
Try<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>error</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>. 
| Improve this Doc View Source

Lift<A, B>(Func<A, B>)

Lifts the specified <em>func</em> into a form which can be applied to
an instance of <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> instead of <em>A</em>.
Declaration
[NotNull]
public static Func<Try<A>, Try<B>> Lift<A, B>([NotNull] Func<A, B> func)
Parameters
Type Name Description
System.Func<A, B> func
Returns
Type Description
System.Func<Try<A>, Try<B>>
Type Parameters
Name Description
A
B
Exceptions
Type Condition
System.ArgumentNullException
<em>func</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

Lift2<A, B, C>(Func<A, B, C>)

Lifts the specified <em>func</em> into a form which can be applied to
two instance of <xref href="NiceTry.Try`1" data-throw-if-not-resolved="false"></xref> instead of <em>A</em> and <em>B</em>.
Declaration
[NotNull]
public static Func<Try<A>, Try<B>, Try<C>> Lift2<A, B, C>([NotNull] Func<A, B, C> func)
Parameters
Type Name Description
System.Func<A, B, C> func
Returns
Type Description
System.Func<Try<A>, Try<B>, Try<C>>
Type Parameters
Name Description
A
B
C
Exceptions
Type Condition
System.ArgumentNullException
<em>func</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

SelectValues<T>(Try<T>[])

Returns an <xref href="System.Collections.Generic.IEnumerable`1" data-throw-if-not-resolved="false"></xref> that contains only the values contained in
the elements of the specified <em>candidates</em> that represent success.
Declaration
[NotNull]
public static IEnumerable<T> SelectValues<T>([NotNull] params Try<T>[] candidates)
Parameters
Type Name Description
Try<T>[] candidates
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>candidates</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

SelectValues<T>(IEnumerable<Try<T>>)

Returns an <xref href="System.Collections.Generic.IEnumerable`1" data-throw-if-not-resolved="false"></xref> that contains only the values contained in
the elements of the specified <em>candidates</em> that represent success.
Declaration
[NotNull]
public static IEnumerable<T> SelectValues<T>([NotNull] IEnumerable<Try<T>> candidates)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Try<T>> candidates
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>candidates</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

Success<T>(T)

Wraps the specified <em>value</em> in a new <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref>. 
Declaration
[NotNull]
public static Try<T> Success<T>([CanBeNull] T value)
Parameters
Type Name Description
T value
Returns
Type Description
Try<T>
Type Parameters
Name Description
T
| Improve this Doc View Source

Switch<T>(Try<T>[])

Searches the specified <em>candidates</em> for the first success. If no
success can be found, a <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> is returned.
Declaration
[NotNull]
public static Try<T> Switch<T>([NotNull] params Try<T>[] candidates)
Parameters
Type Name Description
Try<T>[] candidates
Returns
Type Description
Try<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>candidates</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

Switch<T>(IEnumerable<Try<T>>)

Searches the specified <em>candidates</em> for the first success. If no
success can be found, a <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> is returned.
Declaration
[NotNull]
public static Try<T> Switch<T>([NotNull] IEnumerable<Try<T>> candidates)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Try<T>> candidates
Returns
Type Description
Try<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>candidates</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

To(Action)

Tries to execute the specified <em>work</em> synchronously. If an
exception is thrown a <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> is returned otherwise a <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref>.
Declaration
[NotNull]
public static Try<Unit> To([NotNull] Action work)
Parameters
Type Name Description
System.Action work
Returns
Type Description
Try<TheVoid.Unit>
Exceptions
Type Condition
System.ArgumentNullException
<em>work</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>. 
| Improve this Doc View Source

To<T>(Func<T>)

Tries to execute the specified <em>work</em> synchronously and return its
result. If an exception is thrown a <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> is returned
otherwise a <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref>.
Declaration
[NotNull]
public static Try<T> To<T>([NotNull] Func<T> work)
Parameters
Type Name Description
System.Func<T> work
Returns
Type Description
Try<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>work</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| Improve this Doc View Source

To<T>(Func<Try<T>>)

Tries to execute the specified <em>work</em> synchronously and return its
result. If an exception is thrown or <em>work</em> returns
<xref uid="langword_csharp_null" name="null" href=""></xref>, a <xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref> is returned otherwise a <xref href="NiceTry.Success`1" data-throw-if-not-resolved="false"></xref>.
Declaration
[NotNull]
public static Try<T> To<T>([NotNull] Func<Try<T>> work)
Parameters
Type Name Description
System.Func<Try<T>> work
Returns
Type Description
Try<T>
Type Parameters
Name Description
T
Exceptions
Type Condition
System.ArgumentNullException
<em>work</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
System.ArgumentException
<em>work</em> produces <xref uid="langword_csharp_null" name="null" href=""></xref>.
| 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.Success`1" data-throw-if-not-resolved="false"></xref> containing the result or a
<xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref>, depending on the outcome of the 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
Exceptions
Type Condition
System.ArgumentNullException
<em>createDisposable</em> or <em>useDisposable</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| 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.Success`1" data-throw-if-not-resolved="false"></xref> containing the result or a
<xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref>, depending on the outcome of the 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
System.Func<Disposable, T> useDisposable
Returns
Type Description
Try<T>
Type Parameters
Name Description
Disposable
T
Exceptions
Type Condition
System.ArgumentNullException
<em>createDisposable</em> or <em>useDisposable</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
| 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.Success`1" data-throw-if-not-resolved="false"></xref> containing the result or a
<xref href="NiceTry.Failure`1" data-throw-if-not-resolved="false"></xref>, depending on the outcome of the 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
System.Func<Disposable, Try<T>> useDisposable
Returns
Type Description
Try<T>
Type Parameters
Name Description
Disposable
T
Exceptions
Type Condition
System.ArgumentNullException
<em>createDisposable</em> or <em>useDisposable</em> is <xref uid="langword_csharp_null" name="null" href=""></xref>.
Back to top Copyright © 2015-2016 Microsoft
Generated by DocFX