• API Reference

    Show / Hide Table of Contents
    • Recore
      • AbsoluteUri
      • AsyncAction
      • AsyncAction<T>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8, T9>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7, T8>
      • AsyncAction<T1, T2, T3, T4, T5, T6, T7>
      • AsyncAction<T1, T2, T3, T4, T5, T6>
      • AsyncAction<T1, T2, T3, T4, T5>
      • AsyncAction<T1, T2, T3, T4>
      • AsyncAction<T1, T2, T3>
      • AsyncAction<T1, T2>
      • AsyncDefer
      • AsyncFunc<T, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, T7, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, T6, TResult>
      • AsyncFunc<T1, T2, T3, T4, T5, TResult>
      • AsyncFunc<T1, T2, T3, T4, TResult>
      • AsyncFunc<T1, T2, T3, TResult>
      • AsyncFunc<T1, T2, TResult>
      • AsyncFunc<TResult>
      • Defer
      • Either
      • Either<TLeft, TRight>
      • Func
      • ObjectExtensions
      • Of<T>
      • OfJsonAttribute
      • Optional
      • Optional<T>
      • RelativeUri
      • Result
      • Result.AsyncCatcher<TValue>
      • Result.Catcher<TValue>
      • Result<TValue, TError>
      • Unit
      • UriExtensions
    • Recore.Collections.Generic
      • AnonymousEqualityComparer<T>
      • ICollectionExtensions
      • IDictionaryExtensions
      • IIterator<T>
      • Iterator
      • LinkedListExtensions
      • ListExtensions
      • MappedComparer<T, TMapped>
      • MappedEqualityComparer<T, TMapped>
    • Recore.Linq
      • Renumerable
    • Recore.Security.Cryptography
      • SecureCompare
    • Recore.Text.Json.Serialization.Converters
      • OverrideEitherConverter<TLeft, TRight>
      • OverrideResultConverter<TValue, TError>
    • Recore.Threading.Tasks
      • TaskExtensions

    Struct Unit

    A type with only one value.

    Implements
    IEquatable<Unit>
    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.ReferenceEquals(Object, Object)
    Namespace: Recore
    Assembly: Recore.dll
    Syntax
    public struct Unit : IEquatable<Unit>
    Remarks

    Whereas Void is a type with no values, Unit is a type with one value. It is useful when designing generic types or methods so that a non-generic version does not have to be provided. It is also useful for fluent interfaces (such as LINQ) so that a chain of method calls does not have to be broken by a Void-returning call.

    Examples

    Imagine a type ApiResult<T> that wraps the deserialized JSON response from a REST API. Without Unit, you'd have to define a separate, non-generic ApiResult type for when the response doesn't have a body:

    ApiResult postResult = await PostPersonAsync(person);
    ApiResult<Person> getResult = await GetPersonAsync(id);
    

    With Unit, you can just reuse the same type:

    ApiResult<Unit> postResult = await PostPersonAsync(person);
    ApiResult<Person> getResult = await GetPersonAsync(id);
    

    In the definition of PostPersonAsync(), just return Unit.Value:

    ApiResult<Unit> PostPersonAsync(Person person)
    {
        // ...
        return new ApiResult<Unit>(Unit.Value);
    }
    

    Properties

    | Improve this Doc View Source

    Value

    The singleton Unit value.

    Declaration
    public static Unit Value { get; }
    Property Value
    Type Description
    Unit

    Methods

    | Improve this Doc View Source

    Close(Action)

    Converts a return type of Void to a return type of Unit.

    Declaration
    public static Func<Unit> Close(Action action)
    Parameters
    Type Name Description
    Action action
    Returns
    Type Description
    Func<Unit>
    | Improve this Doc View Source

    Equals(Unit)

    Two unit instances are always equal.

    Declaration
    public bool Equals(Unit other)
    Parameters
    Type Name Description
    Unit other
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    Equals(Object)

    Determines whether another object is the unit value.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj
    Returns
    Type Description
    Boolean
    Overrides
    ValueType.Equals(Object)
    | Improve this Doc View Source

    GetHashCode()

    Returns the hash code of the unit value.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32
    Overrides
    ValueType.GetHashCode()
    | Improve this Doc View Source

    ToString()

    Returns a string representation of the unit value.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    ValueType.ToString()

    Operators

    | Improve this Doc View Source

    Equality(Unit, Unit)

    Two unit instances are always equal.

    Declaration
    public static bool operator ==(Unit lhs, Unit rhs)
    Parameters
    Type Name Description
    Unit lhs
    Unit rhs
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    Inequality(Unit, Unit)

    Two unit instances are always equal.

    Declaration
    public static bool operator !=(Unit lhs, Unit rhs)
    Parameters
    Type Name Description
    Unit lhs
    Unit rhs
    Returns
    Type Description
    Boolean

    Implements

    System.IEquatable<T>

    Extension Methods

    ObjectExtensions.StaticCast<T>(T)
    ObjectExtensions.Apply<T, TResult>(T, Func<T, TResult>)
    ObjectExtensions.Apply<T>(T, Action<T>)
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX