Interface ISingleResultOpt
Type for results of a single-element filter operation which represents a result count of zero, one, or more than one element.
Inherited Members
Namespace: Hgk.Zero.Options
Assembly: Hgk.Zero.Options.dll
Syntax
public interface ISingleResultOpt : IOpt, IEnumerable
Remarks
ISingleResultOpt is a supertype of ISingleResultOpt<T>, the type returned by the single-element filter operations WhereSingle<TSource>(IEnumerable<TSource>) and WhereSingle<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>). If such an operation finds zero elements or one element, a single-result option behaves the same as an ordinary IOpt. However, if such an operation finds more than one element, it behaves differently:
- Resolving a single-result option as an ordinary option ( IOpt) or enumerable ( IEnumerable) will result in an InvalidOperationException. Operations that resolve immediately (such as a langword_csharp_foreach loop, ResolveUntypedOption<TResult>(Func<Boolean, Object, TResult>), or FixUntyped(IOpt)) will cause the exception to be thrown immediately, while deferred operations (such as OfType<TResult>(IOpt)) will cause the exception to be thrown when they are resolved themselves.
- Explicit operations such as ResolveUntypedSingleResultOption<TResult>(Func<Boolean, Boolean, Object, TResult>) can be used to convert a single-result option to another kind of value without throwing an exception.
The following is information about the contract for this interface.
- ResolveUntypedSingleResultOption<TResult>(Func<Boolean, Boolean, Object, TResult>) must be implemented as specified.
-
ISingleResultOpt implements IEnumerable. The contract of this
interface requires that the enumerator returned from GetEnumerator()
behave as follows:
- If the operation produced no elements, the enumeration produces zero elements.
- If the operation produced one element, the enumeration produces that one element.
- If the operation produced more than one element, the enumeration throws InvalidOperationException instead of producing any elements. (The throwing of the exception should be deferred to the first MoveNext() rather than occurring immediately.)
Behavior is undefined if the enumerable produces more than one value.
Methods
| Improve this Doc View SourceResolveUntypedSingleResultOption<TResult>(Func<Boolean, Boolean, Object, TResult>)
Resolves the Object-typed contents of this single result option, producing a result using the specified result selector.
Declaration
TResult ResolveUntypedSingleResultOption<TResult>(Func<bool, bool, object, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
Func<Boolean, Boolean, Object, TResult> | resultSelector | A transform function that accepts an is-valid-option flag, a has-value flag, and a value. |
Returns
Type | Description |
---|---|
TResult | The result of calling resultSelector on the current resolved state of this single result option. |
Type Parameters
Name | Description |
---|---|
TResult | The return type of |
Remarks
The resolver function accepts three parameters: An is-valid-option flag, a has-value flag, and a value.
- If this single result option represents one result, the is-valid-option flag and has-value flag are true and the value parameter is the result value.
- If this single result option represents zero results, the is-valid-option flag is true, the has-value flag is false, and the value parameter is undefined.
- If this single result option represents more than one result (and is thus not a valid option), the is-valid-option flag is false and the remaining parameters are undefined.
If the has-value flag or the value parameter is undefined, the caller must not use their values. To prevent accidental misuse, the implementation should supply false or null, respectively, but this is not required.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|