Last active
July 20, 2018 18:17
-
-
Save lfgrando/a0f939670657f82ea962e093a5c5d8cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static object GetPropValue(object obj, string name) | |
{ | |
foreach (var part in name.Split('.')) | |
{ | |
if (obj == null) { return null; } | |
Type type = obj.GetType(); | |
PropertyInfo info = type.GetProperty(part); | |
if (info == null) { return null; } | |
obj = info.GetValue(obj, null); | |
} | |
return obj; | |
} | |
public static object GetFieldValue(object obj, string name, BindingFlags? bindingFlags = null) | |
{ | |
foreach (var part in name.Split('.')) | |
{ | |
if (obj == null) | |
return null; | |
FieldInfo[] fields = bindingFlags != null ? obj.GetType().GetFields(bindingFlags.Value) : obj.GetType().GetFields(); | |
FieldInfo field = fields.FirstOrDefault(x => x.Name.Equals(part)); | |
if (field == null) | |
return null; | |
object value = field.GetValue(obj); | |
if (value == null) | |
return null; | |
obj = value; | |
} | |
return obj; | |
} | |
var readRow = (string)Tools.GetFieldValue(parser, "m_DelimiterRegex.runnerref._ref.runtext", BindingFlags.NonPublic | BindingFlags.Instance); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment