That will work fine (no exception). Extension methods don't use virtual calls (i.e. it uses the "call" il instruction, not "callvirt") so there is no null check unless you write it yourself in the extension method. This is actually useful in a few cases:
public static bool IsNullOrEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
public static void ThrowIfNull<T>(this T obj, string parameterName)
where T : class
{
if(obj == null) throw new ArgumentNullException(parameterName);
}
etc
Fundamentally, calls to static calls are very literal - i.e.
string s = ...
if(s.IsNullOrEmpty()) {...}
becomes:
string s = ...
if(YourExtensionClass.IsNullOrEmpty(s)) {...}
where there is obviously no null check.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…