Extension Methods

Information

null

Extension methods don't use virtual calls (i.e. it uses the "call" il instruction, not "callvirt"). null object's extension method calls do not generate exception. You have to check null in the extension method.

Object

ThrowIfNull()

public static void ThrowIfNull<T>(this T obj, string parameterName)
        where T : class
{
    if(obj == null) throw new ArgumentNullException(parameterName);
}

ToJson()

public static string ToJson(this object @this, Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.Indented)
{
    return Newtonsoft.Json.JsonConvert.SerializeObject(@this, formatting);
}

Dump()

public static string Dump<T>(this T obj) {
    using (var writer = LINQPad.Util.CreateXhtmlWriter(true, 1))
    {
        writer.Write(obj);
        return writer.ToString();
    }
}

String

IsNullOrEmpty

public static bool IsNullOrEmpty(this string value)
{
    return string.IsNullOrEmpty(value);
}

results matching ""

    No results matching ""