add defaultValue parameter to keyAs
This commit is contained in:
parent
5518abc00b
commit
0a23d914f7
1 changed files with 5 additions and 6 deletions
11
initial.d
11
initial.d
|
@ -229,16 +229,15 @@ struct INISection
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
+ Using `std.conv`, converts the value of the given key
|
+ Using `std.conv`, converts the value of *k* to *T*.
|
||||||
+ to the given type. On conversion failure throws an
|
+ On conversion failure throws an `INITypeException`
|
||||||
+ `INITypeException` with a message containing location
|
+ with a message containing location information.
|
||||||
+ information.
|
|
||||||
+/
|
+/
|
||||||
T
|
T
|
||||||
keyAs(T)(string k)
|
keyAs(T)(string k, string defaultValue = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
return key(k).to!T();
|
return key(k, defaultValue).to!T();
|
||||||
catch (ConvException)
|
catch (ConvException)
|
||||||
throw new INITypeException(
|
throw new INITypeException(
|
||||||
format!"unable to convert [%s].%s to %s"(name, k, T.stringof));
|
format!"unable to convert [%s].%s to %s"(name, k, T.stringof));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue