• 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

    Class Of<T>

    Abstract base class for defining types that alias an existing type.

    Inheritance
    Object
    Of<T>
    Implements
    IEquatable<Of<T>>
    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Namespace: Recore
    Assembly: Recore.dll
    Syntax
    [JsonConverter(typeof(OfConverter))]
    public abstract class Of<T> : IEquatable<Of<T>>
    Type Parameters
    Name Description
    T
    Remarks

    Use Of<T> to create a strongly-typed "alias" of another type.

    You can use a using directive to create an alias for a type, but the scope of that alias is limited to that file. Furthermore, the alias is just that -- an alias -- not a separate type. So, an alias won't prevent errors like this:

    using Name = string;
    using Address = string;
    class Person
    {
        public Person(int age, Address address, Name name)
        {
        }
    }
    
    var person = new Person(22, "Alice", "1 Microsoft Way"); // oops!

    Note: as of C# 9, you can replace many use cases for Of<T> with record types:

    record Address(string Value);
    record Name(string Value);

    Of<T> is not marked with ObsoleteAttribute because records have some limitations that classes do not have. Also, Of<T> provides easy JSON serialization and implicit conversion to its wrapped type, which records do not provide.

    Examples
    class Address : Of<string> {}
    
    var address = new Address { Value = "1 Microsoft Way" };
    Console.WriteLine(address); // prints "1 Microsoft Way"
    
    var address2 = new Address { Value = "1 Microsoft Way" };
    Console.WriteLine(address == address2); // prints "true"
    

    You can add OfJsonAttribute so that the type is serialized in the same was as the T type:

    using System.Text.Json;
    
    [OfJson(typeof(JsonAddress), typeof(string))]
    class JsonAddress : Of<string> {}
    
    var jsonAddress = new JsonAddress { Value = "1 Microsoft Way" };
    Console.WriteLine(JsonSerializer.Serialize(address)); // {"value":"1 Microsoft Way"}
    Console.WriteLine(JsonSerializer.Serialize(jsonAddress)); // "1 Microsoft Way"
    

    Properties

    | Improve this Doc View Source

    Value

    The underlying instance of the wrapped type.

    Declaration
    public T Value { get; }
    Property Value
    Type Description
    T

    Methods

    | Improve this Doc View Source

    Equals(Of<T>)

    Determines whether two instances of the type are equal.

    Declaration
    public bool Equals(Of<T> other)
    Parameters
    Type Name Description
    Of<T> other
    Returns
    Type Description
    Boolean
    Remarks

    Note that instances of two separate subtypes of Of<T> will compare equal to each other if their values are the same type and are equal.

    | Improve this Doc View Source

    Equals(Object)

    Determines whether this instance is equal to another object.

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

    GetHashCode()

    Returns the hash code for the underlying object.

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

    To<TOf>()

    Converts this Of<T> to another subtype of Of<T> with the same value of T.

    Declaration
    public TOf To<TOf>()
        where TOf : Of<T>, new()
    Returns
    Type Description
    TOf
    Type Parameters
    Name Description
    TOf
    | Improve this Doc View Source

    ToString()

    Returns the string representation for the underlying object.

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

    Operators

    | Improve this Doc View Source

    Equality(Of<T>, Of<T>)

    Determines whether two instances of the type are equal.

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

    Implicit(Of<T> to T)

    Converts an instance of Of<T> to its inner type T.

    Declaration
    public static implicit operator T(Of<T> of)
    Parameters
    Type Name Description
    Of<T> of
    Returns
    Type Description
    T
    Remarks

    Of<T> is conceptually (though not in fact) a subtype of T. This conversion allows instances of Of<T> to work with methods out of the caller's control.

    | Improve this Doc View Source

    Inequality(Of<T>, Of<T>)

    Determines whether two instances of the type are not equal.

    Declaration
    public static bool operator !=(Of<T> lhs, Of<T> rhs)
    Parameters
    Type Name Description
    Of<T> lhs
    Of<T> 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