avoid converting objects twice
If I have an object of type T and want to set it as the default value for a call to .keyAs(), I have to convert it to a string first. This string would then get converted again in case the key doesn't exist in the section.
This commit is contained in:
parent
baafe10b17
commit
c00e0fa7e6
1 changed files with 2 additions and 2 deletions
|
@ -234,10 +234,10 @@ struct INISection
|
||||||
+ with a message containing location information.
|
+ with a message containing location information.
|
||||||
+/
|
+/
|
||||||
T
|
T
|
||||||
keyAs(T)(string k, string defaultValue = null)
|
keyAs(T)(string k, T defaultValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
return key(k, defaultValue).to!T();
|
return k in keys ? keys[k].to!T() : defaultValue;
|
||||||
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