Class NameValueCollectionExtensions
Useful extension methods for System.Collections.Specialized.NameValueCollection.
Inheritance
Inherited Members
Namespace: Libplanet.Common
Assembly: Libplanet.Common.dll
Syntax
public static class NameValueCollectionExtensions
Methods
| Improve this Doc View SourceGetBoolean(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 |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
System.Boolean | defaultValue | Returns this value if the specified key
|
Returns
Type | Description |
---|---|
System.Boolean | A System.Boolean value converted from the text value associated with
the specified key |
GetEnum<T>(NameValueCollection, String, T)
Tries to get the text associated with the specified name
as
given System.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 |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
T | defaultValue | Returns this value if the specified key
|
Returns
Type | Description |
---|---|
T | A |
Type Parameters
Name | Description |
---|---|
T | The System.Enum type to parse to. |
GetEnum<T>(NameValueCollection, String)
Tries to get the text associated with the specified name
as
given System.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 |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
Returns
Type | Description |
---|---|
System.Nullable<T> | A |
Type Parameters
Name | Description |
---|---|
T | The System.Enum type to parse to. |
Remarks
This method assumes the collection
contains zero or
one entry for the specified name
.
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the value cannot be parsed to type
|
GetInt32(NameValueCollection, String, Int32)
Tries to get the numeric text associated with the specified name
as
an System.Int32 value from the specified name-value collection
.
Declaration
public static int GetInt32(this NameValueCollection collection, string name, int defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
System.Int32 | defaultValue | Returns this value if the specified key
|
Returns
Type | Description |
---|---|
System.Int32 | An System.Int32 value converted from the text value associated with
the specified key |
GetInt32(NameValueCollection, String)
Tries to get the numeric text associated with the specified name
as
an System.Int32 value from the specified name-value collection
.
Declaration
public static int? GetInt32(this NameValueCollection collection, string name)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
Returns
Type | Description |
---|---|
System.Nullable<System.Int32> | An System.Int32 value converted from the text value associated with
the specified key |
Remarks
This method assumes the collection
contains zero or
one entry for the specified name
.
Exceptions
Type | Condition |
---|---|
System.FormatException | Thrown when the value is not a numeric text. |
System.OverflowException | Thrown when the value is outside the range of the System.Int32 type. |
GetUInt64(NameValueCollection, String, UInt64)
Tries to get the numeric text associated with the specified name
as
a System.UInt64 value from the specified name-value collection
.
Declaration
public static ulong GetUInt64(this NameValueCollection collection, string name, ulong defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
System.UInt64 | defaultValue | Returns this value if the specified key
|
Returns
Type | Description |
---|---|
System.UInt64 | An System.Int32 value converted from the text value associated with
the specified key |
GetUInt64(NameValueCollection, String)
Tries to get the numeric text associated with the specified name
as
a System.UInt64 value from the specified name-value collection
.
Declaration
public static ulong? GetUInt64(this NameValueCollection collection, string name)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NameValueCollection | collection | The System.Collections.Specialized.NameValueCollection that contains the entry to find. |
System.String | name | The System.String key of the entry that contains the value to find. |
Returns
Type | Description |
---|---|
System.Nullable<System.UInt64> | A System.UInt64 value converted from the text value associated with
the specified key |
Remarks
This method assumes the collection
contains zero or
one entry for the specified name
.
Exceptions
Type | Condition |
---|---|
System.FormatException | Thrown when the value is not a numeric text. |
System.OverflowException | Thrown when the value is outside the range of the System.UInt64 type. |