Provides static utility methods to create Cadenza.Either<TValue, Exception> instances.
This type is thread safe.
Use the Either.TryParse methods if it is necessary to know why the value couldn't be parsed. Otherwise, use the Maybe.TryParse methods.
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
See Also: Inherited members from object.
⊟ Public Methods
staticTryConvert<TResult> (object) : Either<TResult, Exception> Documentation for this section has not yet been entered. staticTryConvert<TSource,TResult> (TSource) : Either<TResult, Exception> Attempt to convert the value within a TSource into an instance of type TResult. staticTryParse<T> (string) : Either<T, Exception> Attempt to convert the value within a string into an instance of type T.
⊟ TryConvert<TResult> Generic Method
Documentation for this section has not yet been entered.
public static Either<TResult, Exception> TryConvert<TResult> (object value)⊟ Type Parameters
- TResult
- Documentation for this section has not yet been entered.
⊟ Parameters
- value
- Documentation for this section has not yet been entered.
⊟ Returns
Documentation for this section has not yet been entered.⊟ Exceptions
Type Reason ArgumentNullException Documentation for this section has not yet been entered. ⊟ Remarks
Documentation for this section has not yet been entered.⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ TryConvert<TSource,TResult> Generic Method
Attempt to convert the value within a TSource into an instance of type TResult.
public static Either<TResult, Exception> TryConvert<TSource, TResult> (TSource value)⊟ See Also
⊟ Type Parameters
- TSource
- The type to convert from.
- TResult
- The type to convert to.
⊟ Parameters
- value
- An instance of type TSource containing the value to convert into a TResult instance.
⊟ Returns
A Cadenza.Either<``1, Exception> containing either the parsed value or the error that results from attempting to convert value into an instance of type TResult.⊟ Remarks
TryParse attempts to use a variety of mechanisms to convert value into a TResult, attempting, in order:
- TypeDescriptor.GetConverter(typeof(TResult)).ConvertFrom(value)
- TypeDescriptor.GetConverter(typeof(TSource)).ConvertTo(value, typeof(TResult))
- Convert.ChangeType(value, typeof(TResult))
If none of these methods are able to convert the value, then the returned Cadenza.Either<TSource, Exception> will contain a NotSupportedException, and Exception.InnerException will contain the original exception.
C# Example Either<DateTime, Exception> a = Either.TryConvert<int, DateTime> (42); Exception e = a.Fold (i => null, i => i); Assert.IsNotNull (e); Assert.IsTrue (typeof (Exception).IsAssignableFrom (e.GetType())); Either<string, Exception> b = Either.TryConvert<int, string> (42); string n2 = b.Fold (i => i, i => null); Assert.AreEqual ("42", n2); Either<int, Exception> c = Either.TryConvert<CustomConvertible, int> (new CustomConvertible ()); int n3 = c.Fold (i => i, i => -1); Assert.AreEqual (CustomConvertible.Int32, n3);⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ TryParse<T> Generic Method
Attempt to convert the value within a string into an instance of type T.
public static Either<T, Exception> TryParse<T> (string value)⊟ Type Parameters
- T
- The type to convert value to.
⊟ Parameters
- value
- A string containing the value to convert into a T.
⊟ Returns
A Cadenza.Either<``0, Exception> containing either the parsed value or the error that results from attempting to convert value into an instance of type T.⊟ Remarks
This method calls Either.TryConvert``2(``0), with string as the TSource type.
C# Example var v = Either.TryParse<int> ("3.14159"); var e = v.Fold (i => null, i => i); Assert.IsNotNull (e); Assert.IsTrue (typeof(Exception).IsAssignableFrom (e.GetType())); v = Either.TryParse<int> ("42"); var n = v.Fold (i => i, i => -1); Assert.AreEqual (42, n); var v2 = Either.TryParse<int?> ("3.14159"); e = v2.Fold (i => null, i => i); Assert.IsNotNull (e); Assert.IsTrue (typeof(Exception).IsAssignableFrom (e.GetType())); v2 = Either.TryParse<int?> ("42"); n = v2.Fold (i => i.Value, i => -1); Assert.AreEqual (42, n);⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0