/// <summary> /// Use Reflect get value of current <paramref name="value" /> by <paramref name="name" /> /// </summary> /// <param name="value">current value</param> /// <param name="name">field or property /// <para>e.g.: 'a.b.c'</para> /// </param> /// <returns></returns> public static object Value(this object value, string name) { bool flag = value == null || value == DBNull.Value || string.IsNullOrEmpty(name); object result; if (flag) { result = null; } else { string[] names = name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); object _value = value; foreach (string i in names) { Func <object, string, bool, object, object> @delegate = FastExpressions.CreateDelegate(_value); bool flag2 = @delegate != null; if (flag2) { _value = @delegate(_value, i, false, null); } bool flag3 = _value == null; if (flag3) { break; } } result = _value; } return(result); }
public static Func <object, string, bool, object, object> CreateDelegate(object @object) { if (@object == null) { return(null); } var type = @object.GetType(); return(GetterSetters.GetOrAdd(type, _func => { var exp = new FastExpressions(@object); return exp.GenerateExpressions(); })); }
public static Func <object, string, bool, object, object> CreateDelegate(object @object) { bool flag = @object == null; Func <object, string, bool, object, object> result; if (flag) { result = null; } else { Type type = @object.GetType(); result = FastExpressions.GetterSetters.GetOrAdd(type, delegate(Type _func) { FastExpressions exp = new FastExpressions(@object); return(exp.GenerateExpressions()); }); } return(result); }
{/// <summary> /// Use Reflect get value of current <paramref name="value"/> by <paramref name="name"/> /// </summary> /// <param name="value">current value</param> /// <param name="name">field or property /// <para>e.g.: 'a.b.c'</para> /// </param> /// <returns></returns> public static object Value(this object value, string name) { if (value == null || value == DBNull.Value || string.IsNullOrEmpty(name)) { return(null); } var names = name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); object _value = value; foreach (string n in names) { var @delegate = FastExpressions.CreateDelegate(_value); if (@delegate != null) { _value = @delegate(_value, n, false, null); } if (_value == null) { break; } } return(_value); }