I have been using an Extension function to make life easier for checking null parameters and throwing subsequent ArgumentNullExceptions. The function will also return the value being checked, allowing for some slick chaining.
I am now concerned that this extension function (which is used a lot) may not be as memory performant as it could be due to the possible lack of inlining.
Questions
- Is this function inlined, and how is that determined?
- If not inlined, then what are the ramifications? Consider this function is already used hundreds of times in just the base code set.
Extension Function
public static class ValueExtensions
{
public static T CheckNull<T>([NotNull] this T? argument, [CallerArgumentExpression("argument")] string? paramName = null)
{
if (argument is null) {
throw new ArgumentNullException(paramName);
}
return argument;
}
}
Use Case
public class MyClass
{
public void SomeFunction(OtherClass arg1) => arg1.CheckNull().DoSomething();
}
Vs
public class MyClass
{
public void SomeFunction(OtherClass arg1)
{
arg1.CheckNull();
arg1.DoSomething();
}
}