• CacheManager
  • Documentation
  • Api Docs
  • MichaCo.net
    Show / Hide Table of Contents

    Class Guard

    Utility class to do null and other checks.

    Inheritance
    Object
    Guard
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace:CacheManager.Core.Utility
    Assembly:CacheManager.Core.dll
    Syntax
    public static class Guard

    Methods

    | Improve this Doc View Source

    Ensure(Boolean, String, Object[])

    Validates that condition is true and otherwise throws an exception.

    Declaration
    public static bool Ensure(bool condition, string message, params object[] args)
    Parameters
    Type Name Description
    Boolean condition

    The condition to validate.

    String message

    The message to throw if the configuration is false.

    Object[] args

    string.Format will be used to format message and args to create the exception message.

    Returns
    Type Description
    Boolean

    true if the condition is valid.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if condition is false.

    | Improve this Doc View Source

    EnsureNotNull<T>(T, String, Object[])

    Validates that value is not null and otherwise throws an exception. Structs are allowed although value cannot be null in this case.

    Declaration
    public static T EnsureNotNull<T>([ValidatedNotNull] T value, string message, params object[] args)where T : class
    Parameters
    Type Name Description
    T value

    The value to validate.

    String message

    The message to throw if the value is null.

    Object[] args

    string.Format will be used to format message and args to create the exception message.

    Returns
    Type Description
    T

    The value if not null.

    Type Parameters
    Name Description
    T

    The type of value.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if value is null.

    | Improve this Doc View Source

    NotNull<T>(T, String)

    Validates that value is not null and otherwise throws an exception. Structs are allowed although value cannot be null in this case.

    Declaration
    public static T NotNull<T>([ValidatedNotNull] T value, string parameterName)
    Parameters
    Type Name Description
    T value

    The parameter value to validate.

    String parameterName

    The parameter name.

    Returns
    Type Description
    T

    The value, if not null.

    Type Parameters
    Name Description
    T

    The type of value.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if value is null.

    | Improve this Doc View Source

    NotNullOrEmpty(String, String)

    Validates that value is not null or empty and otherwise throws an exception.

    Declaration
    public static string NotNullOrEmpty([ValidatedNotNull] string value, string name)
    Parameters
    Type Name Description
    String value

    The parameter value to validate.

    String name

    The parameter name.

    Returns
    Type Description
    String

    The value, if not null or empty.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if value is null.

    ArgumentException

    Thrown if value is empty.

    | Improve this Doc View Source

    NotNullOrEmpty<T>(ICollection<T>, String)

    Validates that value is not null or empty and otherwise throws an exception.

    Declaration
    public static ICollection<T> NotNullOrEmpty<T>([ValidatedNotNull] ICollection<T> value, string name)
    Parameters
    Type Name Description
    ICollection<T> value

    The parameter value to validate.

    String name

    The parameter name.

    Returns
    Type Description
    ICollection<T>

    The value, if not null or empty.

    Type Parameters
    Name Description
    T

    Type of the collection.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if value is null.

    ArgumentException

    Thrown if value is empty.

    | Improve this Doc View Source

    NotNullOrWhiteSpace(String, String)

    Validates that value is not null, empty or contains whitespace only and otherwise throws an exception.

    Declaration
    public static string NotNullOrWhiteSpace([ValidatedNotNull] string value, string name)
    Parameters
    Type Name Description
    String value

    The parameter value to validate.

    String name

    The parameter name.

    Returns
    Type Description
    String

    The value if not null or empty.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if value is null.

    ArgumentException

    Thrown if value is empty.

    • Improve this Doc
    • View Source
    © 2025 by Michael Conrad. All rights reserved. - MichaCo.net