Class LambdaConfig
The LambdaRead*
methods.
Inheritance
Namespace: LambdaSharp
Assembly: LambdaSharp.dll
Syntax
public sealed class LambdaConfig
Constructors
LambdaConfig(ILambdaConfigSource)
Create a new instance using the provided ILambda
Declaration
public LambdaConfig(ILambdaConfigSource source)
Parameters
Type | Name | Description |
---|---|---|
ILambda |
source | The ILambda |
Exceptions
Type | Condition |
---|---|
System. |
Thrown when |
Properties
Item[String]
Create a new Lambda
Declaration
public LambdaConfig this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
System. |
name | Name of the nested section. |
Property Value
Type | Description |
---|---|
Lambda |
A newly scoped Lambda |
Keys
Enumerate all child keys at the current path in the hierarchy.
Declaration
public IEnumerable<string> Keys { get; }
Property Value
Type | Description |
---|---|
System. |
Enumeration of all nested keys. |
Path
Retrieve the current hierarchy path.
Declaration
public string Path { get; }
Property Value
Type | Description |
---|---|
System. |
Current path. |
Methods
Read<T>(String, Func<String, T>, Func<String, T>, Action<T>)
Read the value for a key from ILambda
Declaration
public T Read<T>(string key, Func<string, T> fallback, Func<string, T> convert, Action<T> validate)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
fallback | An optional callback when the value could not be found at the current path. |
System. |
convert | An optional conversion from string to another type when the value was found. |
System. |
validate | An optional callback to validate the converted value. |
Returns
Type | Description |
---|---|
T | The found value. |
Type Parameters
Name | Description |
---|---|
T | The type of the value after conversion. |
Remarks
This method should rarely be invoked directly. Instead use ReadText(String, Action<String>) and the other convenience methods.
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when no value is found at |
Lambda |
Thrown when the value fails validation. |
ReadCommaDelimitedList(String, Action<IEnumerable<String>>)
Read an enumeration of comma-delimited string
values for a
key at the current path in the hierarchy.
Declaration
public IEnumerable<string> ReadCommaDelimitedList(string key, Action<IEnumerable<string>> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found enumeration of |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when no value is found at |
Lambda |
Thrown when the value fails validation. |
ReadInt(String, Action<Int32>)
Read the int
value for a key at the current path in the hierarchy.
Declaration
public int ReadInt(string key, Action<int> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when no value is found at |
Lambda |
Thrown when the value fails validation. |
ReadInt(String, Int32, Action<Int32>)
Read the int
value for a key at the current path in the hierarchy.
Declaration
public int ReadInt(string key, int defaultValue, Action<int> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
defaultValue | A value to return if |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |
ReadText(String, Action<String>)
Read the string
value for a key at the current path in the hierarchy.
Declaration
public string ReadText(string key, Action<string> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when no value is found at |
Lambda |
Thrown when the value fails validation. |
ReadText(String, String, Action<String>)
Read the string
value for a key at the current path in the hierarchy.
Declaration
public string ReadText(string key, string defaultValue, Action<string> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
defaultValue | A value to return if |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |
ReadTimeSpan(String, Action<TimeSpan>)
Read the TimeSpan
value for a key at the current path in the hierarchy.
Declaration
public TimeSpan ReadTimeSpan(string key, Action<TimeSpan> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when no value is found at |
Lambda |
Thrown when the value fails validation. |
ReadTimeSpan(String, TimeSpan, Action<TimeSpan>)
Read the TimeSpan
value for a key at the current path in the hierarchy.
Declaration
public TimeSpan ReadTimeSpan(string key, TimeSpan defaultValue, Action<TimeSpan> validate = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | The name of the value to read. |
System. |
defaultValue | A value to return if |
System. |
validate | An optional callback to validate the value. |
Returns
Type | Description |
---|---|
System. |
The found |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |
ValidateIsInRange(Int32, Int32)
Creates a callback that validates that a value is in range of the specified lower and upper bounds, inclusively.
Declaration
public static Action<int> ValidateIsInRange(int lowerValue, int upperValue)
Parameters
Type | Name | Description |
---|---|---|
System. |
lowerValue | Lower bound in range. |
System. |
upperValue | Upper bound in range. |
Returns
Type | Description |
---|---|
System. |
The validation callback to validate that a value is within the provided lower and upper bounds. |
ValidateIsNegative(Int32)
Validates that the value is negative.
Declaration
public static void ValidateIsNegative(int value)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | Value to validate. |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |
ValidateIsNonNegative(Int32)
Validates that the value is non-negative.
Declaration
public static void ValidateIsNonNegative(int value)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | Value to validate. |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |
ValidateIsNonPositive(Int32)
Validates that the value is non-positive.
Declaration
public static void ValidateIsNonPositive(int value)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | Value to validate. |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |
ValidateIsPositive(Int32)
Validates that the value is positive.
Declaration
public static void ValidateIsPositive(int value)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | Value to validate. |
Exceptions
Type | Condition |
---|---|
Lambda |
Thrown when the value fails validation. |