Show / Hide Table of Contents

Class NameValueCollectionExtensions

Useful extension methods for NameValueCollection.

Inheritance
Object
NameValueCollectionExtensions
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
System.Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
System.Object.ToString()
Namespace: Libplanet.Common
Assembly: Libplanet.Common.dll
Syntax
public static class NameValueCollectionExtensions

Methods

| Improve this Doc View Source

GetBoolean(NameValueCollection, String, Boolean)

Tries to get the boolean text associated with the specified name as a System.Boolean value from the specified name-value collection.

Supported keywords are: true, false, yes, no, on, off, t, f, y, n, 1, 0 (all case-insensitive).

Declaration
public static bool GetBoolean(this NameValueCollection collection, string name, bool defaultValue = false)
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

System.Boolean defaultValue

Returns this value if the specified key name is not found in the collection, or the associated value is not a valid boolean text. Configured as false by default.

Returns
Type Description
System.Boolean

A System.Boolean value converted from the text value associated with the specified key name from the collection, if found; otherwise, defaultValue.

| Improve this Doc View Source

GetEnum<T>(NameValueCollection, String, T)

Tries to get the text associated with the specified name as given Enum type T value from the specified name-value collection.

Declaration
public static T GetEnum<T>(this NameValueCollection collection, string name, T defaultValue)
    where T : struct, Enum
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

T defaultValue

Returns this value if the specified key name is not found in the collection, or the associated value cannot be parsed to type T.

Returns
Type Description
T

A T value converted from the text value associated with the specified key name from the collection, if found; otherwise, langword_csharp_defaultValue.

Type Parameters
Name Description
T

The Enum type to parse to.

| Improve this Doc View Source

GetEnum<T>(NameValueCollection, String)

Tries to get the text associated with the specified name as given Enum type T value from the specified name-value collection.

Declaration
public static T? GetEnum<T>(this NameValueCollection collection, string name)
    where T : struct, Enum
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

Returns
Type Description
Nullable<T>

A T value converted from the text value associated with the specified key name from the collection, if found; otherwise, null.

Type Parameters
Name Description
T

The Enum type to parse to.

Remarks

This method assumes the collection contains zero or one entry for the specified name.

Exceptions
Type Condition
ArgumentException

Thrown when the value cannot be parsed to type T.

| Improve this Doc View Source

GetInt32(NameValueCollection, String, Int32)

Tries to get the numeric text associated with the specified name as an Int32 value from the specified name-value collection.

Declaration
public static int GetInt32(this NameValueCollection collection, string name, int defaultValue)
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

Int32 defaultValue

Returns this value if the specified key name is not found in the collection, or the associated value is not a numeric text or outside the range of the Int32 type.

Returns
Type Description
Int32

An Int32 value converted from the text value associated with the specified key name from the collection, if found; otherwise, defaultValue.

| Improve this Doc View Source

GetInt32(NameValueCollection, String)

Tries to get the numeric text associated with the specified name as an Int32 value from the specified name-value collection.

Declaration
public static int? GetInt32(this NameValueCollection collection, string name)
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

Returns
Type Description
Nullable<Int32>

An Int32 value converted from the text value associated with the specified key name from the collection, if found; otherwise, null.

Remarks

This method assumes the collection contains zero or one entry for the specified name.

Exceptions
Type Condition
FormatException

Thrown when the value is not a numeric text.

System.OverflowException

Thrown when the value is outside the range of the Int32 type.

| Improve this Doc View Source

GetUInt64(NameValueCollection, String, UInt64)

Tries to get the numeric text associated with the specified name as a UInt64 value from the specified name-value collection.

Declaration
public static ulong GetUInt64(this NameValueCollection collection, string name, ulong defaultValue)
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

UInt64 defaultValue

Returns this value if the specified key name is not found in the collection, or the associated value is not a numeric text or outside the range of the UInt64 type.

Returns
Type Description
UInt64

An Int32 value converted from the text value associated with the specified key name from the collection, if found; otherwise, defaultValue.

| Improve this Doc View Source

GetUInt64(NameValueCollection, String)

Tries to get the numeric text associated with the specified name as a UInt64 value from the specified name-value collection.

Declaration
public static ulong? GetUInt64(this NameValueCollection collection, string name)
Parameters
Type Name Description
NameValueCollection collection

The NameValueCollection that contains the entry to find.

String name

The String key of the entry that contains the value to find.

Returns
Type Description
Nullable<UInt64>

A UInt64 value converted from the text value associated with the specified key name from the collection, if found; otherwise, null.

Remarks

This method assumes the collection contains zero or one entry for the specified name.

Exceptions
Type Condition
FormatException

Thrown when the value is not a numeric text.

System.OverflowException

Thrown when the value is outside the range of the UInt64 type.

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium