public void DoSomething(HttpContextBase context) { context.ThrowIfNull(nameof(context)); // Do something with context }
public void DoSomething() { HttpContext.Current.ThrowIfNull("HttpContext.Current"); // Do something with HttpContext.Current }In this example, the ThrowIfNull method is used to ensure that the static HttpContext.Current property is not null. If it is null, an ArgumentNullException is thrown with a message that includes the name of the property ("HttpContext.Current"). The System.Web.HttpContextBase.ThrowIfNull method is part of the System.Web.Abstractions package library.