I have a setting file that is formatted like so:
[Database]
Host=localhost
Username=root
Password=root
Now, I have a class named Settings
which is a DynamicObject
so I can use dynamic settings. When I parse the file, the key for the dictionary that contains the settings is the header + key. So, for example, the key in the Host
case would be Database.Host
and the value would be localhost
.
Now, I want the user to use it like so:
dynamic settings = new Settings("Config.ini");
string host = settings.Database.Host;
However, when I override TryGetMember
, GetMemberBinder
only contains Name
, and the Name
is Database and not Database.Host as it should be. How can I "split" the GetMemberBinder
Name
property? When I use .
the Name
property doesn't contain what's after the .
.
For example,
when I use:
settings.Database.Host
then
GetBinderName
Name
only contains Database, but it should contain:
Database.Host.
Thanks.
**EDIT: ** I have another question. Let's say I have string name = "Database", and then I do settings.Name.Host. It doesn't resolve Name as Database. Is there a solution to it?