Note that there are some explanatory texts on larger screens.

plurals
  1. POC#: How to enumerate class with nested classes and with all fields
    primarykey
    data
    text
    <p>I have one BIG .ini file. e.c :</p> <pre><code>[Globals] EdgeDkShadowColor = 188 196 218 EdgeFillColor = 244 244 244 [SysMetrics] ActiveCaption = 207 214 232 Background = 58 110 165 Btnface = 244 244 244 ... [Button.Checkbox] AccentColorHint = 250 196 88 Bgtype = imagefile BorderColorHint = 29 82 129 FillColorHint = 33 161 33 ... [Button.Checkbox(Checkeddisabled)] TextColor = 161 161 146 [Button.Checkbox(Mixeddisabled)] TextColor = 161 161 146 [Button.Checkbox(Uncheckeddisabled)] TextColor = 161 161 146 </code></pre> <p>And i create static class. I want enumerate lines of .ini and set value to all fields from class Parameters. </p> <p>Class structure is:</p> <pre><code>public static class Parameters { public static class Globals { public static string EdgeDkShadowColor; public static string EdgeFillColor; ... } public static class SysMetrics { public static string ActiveCaption; public static string Background; public static string Btnface; ... } public static class Button { public static class Checkbox { public static string AccentColorHint; public static string Bgtype; public static string BorderColorHint; } public static class Checkbox_Checkeddisabled { public static string TextColor; } public static class Checkbox_Mixeddisabled { public static string TextColor; } public static class Checkbox_Uncheckeddisabled { public static string TextColor; } ... </code></pre> <p>How can I correctly enumerate all fields from class and initialize them to eventually get an object:</p> <pre><code>Parameters. Globals. EdgeDkShadowColor = "188 196 218"; EdgeFillColor = "244 244 244"; SysMetrics. ActiveCaption = "207 214 232" Background = "58 110 165" Btnface = "244 244 244" ... Button. Checkbox. AccentColorHint = "250 196 88" Bgtype = "imagefile" BorderColorHint = "29 82 129" ... etc. </code></pre> <p>P.S. </p> <ol> <li>All values is string.</li> <li>'(' in name of replaced by '_'.</li> <li>Name of parameter can contain a string "::". It is replaced by "Ext".</li> </ol> <p><strong>UPDATE</strong></p> <p>I found first code of this task. I try to use this function: The main part of the code is </p> <pre><code>StringReader str = new StringReader(fileAsString); string line; Type curType = null; while ((line = str.ReadLine()) != null) { if (string.IsNullOrEmpty(line) | line.StartsWith(";")) continue; if (line.Contains('[')) { line = line[0] + line[1].ToString().ToUpper() + line.Substring(2); var listing = typeof(Parameters).GetNestedTypes().ToList(); string lineS = line.Trim('[').Trim(']').Trim(')'). Replace("(", "_").Replace("::", "Ext").Trim(); var listingOf = listing.Find(tipe =&gt; tipe.Name == lineS); curType = listingOf; } else { if (curType != null) { FieldInfo found = curType.GetField(splits[0].Trim(')').Replace("(", "_").Trim()); if (found != null) found.SetValue(null, splits[1].Trim()); } } } </code></pre> <p>It's work, but only for one level. This is result of work this code:</p> <p><a href="http://postimg.org/image/5s28m4c8h/" rel="nofollow">http://postimg.org/image/5s28m4c8h/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload