Gorgon
Show / Hide Table of Contents

Class GorgonNullExtensions

Extension methods for null checking on reference types and nullable types.

Inheritance
object
GorgonNullExtensions
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Core
Assembly: Gorgon.Core.dll
Syntax
public static class GorgonNullExtensions

Methods

| Edit this page View Source

AsNullable<T>(object)

Function to return the value as a nullable type.

Declaration
public static T? AsNullable<T>(this object value) where T : struct
Parameters
Type Name Description
object value

The value to convert.

Returns
Type Description
T?

The value as a nullable value type.

Type Parameters
Name Description
T

The type of value to convert to, must be a value type.

| Edit this page View Source

IfNull<T>(object, T)

Function to check an object for null or DBNull and return a substitute value.

Declaration
public static T IfNull<T>(this object value, T substitutionValue)
Parameters
Type Name Description
object value

The value to check.

T substitutionValue

The value used to replace the return value if the original value is null or DBNull.

Returns
Type Description
T

The original value if not null (or DBNull), or the substitutionValue otherwise.

Type Parameters
Name Description
T

The type of value.

| Edit this page View Source

IsNull(object)

Determines whether the specified value is null.

Declaration
public static bool IsNull(this object value)
Parameters
Type Name Description
object value

The value to check.

Returns
Type Description
bool

true if the specified value is null; otherwise, false.

Remarks

This will check an object for null and DBNull.

  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author