Skip to content

Object extensions

siof edited this page Oct 23, 2017 · 1 revision

Object extensions

ToStringSafe

string ToStringSafe(this object obj)

string ToStringSafe(this object obj, string defaultValue)

If object is null then returns null or defaultValue, otherwise result of ToString().

IfNotNull

TInput IfNotNull<TInput>(this TInput obj, Action<TInput> evaluator)

TResult IfNotNull<TInput, TResult>(this TInput obj, Func<TInput, TResult> evaluator)

TResult IfNotNull<TInput, TResult>(this TInput obj, Func<TInput, TResult> evaluator, TResult def)

If object is not null then evaluator is colled on this object.

Returned value depends which function was called:

  • TInput IfNotNull<TInput>(this TInput obj, Action<TInput> evaluator)

    Returns object on which function was called

  • TResult IfNotNull<TInput, TResult>(this TInput obj, Func<TInput, TResult> evaluator)

    Returns value returned by evaluator or default(TResult)

  • TResult IfNotNull<TInput, TResult>(this TInput obj, Func<TInput, TResult> evaluator, TResult def)

    Returns value returned by evaluator or given def value

Clone this wiki locally