AdvantageCMS.Core.Common.BaseClasses Namespace
Advantage CSP

ArgumentHelper Class

Provides helper methods for asserting arguments.

Namespace:  AdvantageCMS.Core.Common.SitemapGenerator
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public static class ArgumentHelper

Remarks


This class provides helper methods for asserting the validity of arguments. It can be used to reduce the number of laborious if, throw sequences in your code.

The AssertNotNull<(Of <<'(T>)>>)(T, String) method can be used to ensure that arguments are not nullNothingnullptra null reference (Nothing in Visual Basic). The AssertEnumMember overloads can be used to assert the validity of enumeration arguments.

Examples


The following code ensures that the name argument is not null:
C#
public void DisplayDetails(string name)
{
ArgumentHelper.AssertNotNull(name, "name");
//now we know that name is not null
...
}

Examples


The following code ensures that the day parameter is a valid member of its enumeration:
C#
public void DisplayInformation(DayOfWeek day)
{
ArgumentHelper.AssertEnumMember(day);
//now we know that day is a valid member of DayOfWeek
...
}

Examples


The following code ensures that the day parameter is either DayOfWeek.Monday or DayOfWeek.Thursday:
C#
public void DisplayInformation(DayOfWeek day)
{
ArgumentHelper.AssertEnumMember(day, DayOfWeek.Monday, DayOfWeek.Thursday);
//now we know that day is either Monday or Thursday
...
}

Examples


The following code ensures that the bindingFlags parameter is either BindingFlags.Public, BindingFlags.NonPublic or both:
C#
public void GetInformation(BindingFlags bindingFlags)
{
ArgumentHelper.AssertEnumMember(bindingFlags, BindingFlags.Public, BindingFlags.NonPublic);
//now we know that bindingFlags is either Public, NonPublic or both
...
}

Examples


The following code ensures that the bindingFlags parameter is either BindingFlags.Public, BindingFlags.NonPublic, both or neither (BindingFlags.None):
C#
public void GetInformation(BindingFlags bindingFlags)
{
ArgumentHelper.AssertEnumMember(bindingFlags, BindingFlags.Public, BindingFlags.NonPublic, BindingFlags.None);
//now we know that bindingFlags is either Public, NonPublic, both or neither
...
}

Inheritance Hierarchy


Object
  AdvantageCMS.Core.Common.SitemapGenerator..::..ArgumentHelper