• 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 ObjectExtensions

    Helper methods for working with any object in .NET.

    Inheritance
    Object
    ObjectExtensions
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Recore
    Assembly: Recore.dll
    Syntax
    public static class ObjectExtensions

    Methods

    | Improve this Doc View Source

    Apply<T>(T, Action<T>)

    Invokes an action on an object and passes the object through.

    Declaration
    public static T Apply<T>(this T obj, Action<T> action)
    Parameters
    Type Name Description
    T obj
    Action<T> action
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    | Improve this Doc View Source

    Apply<T, TResult>(T, Func<T, TResult>)

    Invokes a function on an object.

    Declaration
    public static TResult Apply<T, TResult>(this T obj, Func<T, TResult> func)
    Parameters
    Type Name Description
    T obj
    Func<T, TResult> func
    Returns
    Type Description
    TResult
    Type Parameters
    Name Description
    T
    TResult
    Examples

    This method is useful for calling a function with postfix syntax:

    var syncClient = new ServiceCollection()
        .Apply(ConfigureServices)
        .Apply(x => x.BuildServiceProvider())
        .Apply(x => x.GetService<SyncClient>());
    

    It can also be used to simplify null-propagation logic when the ?. operator cannot be used:

    // Before
    var route = contentEndpoint is null ? null : $"{contentEndpoint}?path={forwardSlashPath}";
    
    // After
    var route = contentEndpoint?.Apply(x => $"{x}?path={forwardSlashPath}");
    
    | Improve this Doc View Source

    ApplyAsync<T>(Task<T>, AsyncAction<T>)

    Awaits a task, invokes an asynchronous action on the result, and passes the awaited task through.

    Declaration
    public static Task<T> ApplyAsync<T>(this Task<T> task, AsyncAction<T> action)
    Parameters
    Type Name Description
    Task<T> task
    AsyncAction<T> action
    Returns
    Type Description
    Task<T>
    Type Parameters
    Name Description
    T
    | Improve this Doc View Source

    ApplyAsync<T, TResult>(Task<T>, AsyncFunc<T, TResult>)

    Awaits a task and invokes an asynchronous function on a task.

    Declaration
    public static Task<TResult> ApplyAsync<T, TResult>(this Task<T> task, AsyncFunc<T, TResult> func)
    Parameters
    Type Name Description
    Task<T> task
    AsyncFunc<T, TResult> func
    Returns
    Type Description
    Task<TResult>
    Type Parameters
    Name Description
    T
    TResult
    | Improve this Doc View Source

    StaticCast<T>(T)

    Converts an object's type to T at compile time.

    Declaration
    public static T StaticCast<T>(this T obj)
    Parameters
    Type Name Description
    T obj
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Remarks

    This method is analogous to static_cast in C++. In C#, casting is normally an unsafe operation: a failed cast will throw InvalidCastException. On the other hand, StaticCast<T>(T) will never throw at run time if it compiles.

    Examples

    Useful for overcoming those pesky variance issues:

    Task<IEnumerable<object>> GetObjectsAsync()
    {
        var result = new[] { "hello" };
    
        // error CS0029 because the static type of `result` is an array, not an `IEnumerable`
        // return Task.FromResult(result);
    
        // 👍
        return Task.FromResult(result.StaticCast<IEnumerable<object>>());
    }
    
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX