diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-12-09 16:59:59 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-12-09 16:59:59 +0200 |
| commit | 4417c2eccb3795330144afa39e3bf271652bd31f (patch) | |
| tree | 9a2ebd1c680f12f04e1ecd7b0eaea58236379e81 /Software/Visual_Studio/Tango.CSV/CsvFileReader.cs | |
| parent | 4fb7e23ead019e9c2b573eb4ccc89444fb5a7a6f (diff) | |
| download | Tango-4417c2eccb3795330144afa39e3bf271652bd31f.tar.gz Tango-4417c2eccb3795330144afa39e3bf271652bd31f.zip | |
Dispenser Jid - Test examples. Create DispenserAnalyser utility project. Seal test.
Diffstat (limited to 'Software/Visual_Studio/Tango.CSV/CsvFileReader.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/CsvFileReader.cs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs index 6d1deded2..ec5b07630 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs @@ -240,22 +240,39 @@ namespace Tango.CSV /// <param name="c">The c.</param> /// <param name="staticMember">if set to <c>true</c> [static member].</param> /// <returns></returns> - private static Action<T, string> FindSetter(string c, bool staticMember) + private static Action<T, string> FindSetter(string c, bool staticMember, int? index = null) { var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | (staticMember ? BindingFlags.Static : BindingFlags.Instance); Action<T, string> action = null; + PropertyInfo pi = typeof(T).GetProperty(c, flags); if (pi != null) { var pFunc = StringToObject(pi.PropertyType); action = EmitSetValueAction(pi, pFunc); } - FieldInfo fi = typeof(T).GetField(c, flags); - if (fi != null) + + if (action == null) + { + FieldInfo fi = typeof(T).GetField(c, flags); + if (fi != null) + { + var fFunc = StringToObject(fi.FieldType); + action = EmitSetValueAction(fi, fFunc); + } + } + + if (action == null && index != null) { - var fFunc = StringToObject(fi.FieldType); - action = EmitSetValueAction(fi, fFunc); + var propByIndex = typeof(T).GetProperties(flags).SingleOrDefault(x => x.GetCustomAttribute<CsvOrderAttribute>() != null && x.GetCustomAttribute<CsvOrderAttribute>().Index == index); + + if (propByIndex != null) + { + var pFunc = StringToObject(propByIndex.PropertyType); + action = EmitSetValueAction(propByIndex, pFunc); + } } + return action; } @@ -292,7 +309,7 @@ namespace Tango.CSV Action<T, string> action = null; if (columnName.IndexOf(' ') >= 0) columnName = columnName.Replace(" ", ""); - action = FindSetter(columnName, false) ?? FindSetter(columnName, true); + action = FindSetter(columnName, false, i) ?? FindSetter(columnName, true, i); list.Add(action); } |
