Class NameValueCollectionExtensions
Useful extension methods for NameValueCollection.
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 |
---|---|---|
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
|
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 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
|
Returns
Type | Description |
---|---|
T | A |
Type Parameters
Name | Description |
---|---|
T | The Enum type to parse to. |
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 |
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
|
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
|
Returns
Type | Description |
---|---|
Int32 | An 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 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 |
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. |
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
|
Returns
Type | Description |
---|---|
UInt64 | An 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 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 |
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. |