ObjectExtensionsNewIfNullT Method

Creates a new instance of the specified type if the object reference is null.

Definition

Namespace: DevCase.Extensions.ObjectExtensions
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[EditorBrowsableAttribute(EditorBrowsableState.Always)]
public static T NewIfNull<T>(
	this ref T refObject
)
where T : class

Parameters

refObject  T
The object reference to check for null.

Type Parameters

T
The type of the object reference.

Return Value

T
If the object reference is not null, returns the original object reference.

If the object reference is null, creates a new instance of type T and returns it.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type T. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also