/// <summary> /// 静态构造器 /// </summary> static HttpContentExtensions() { var property = typeof(HttpContent).GetProperty("IsBuffered", BindingFlags.Instance | BindingFlags.NonPublic); if (property != null) { isBuffered = LambdaUtil.CreateGetFunc <HttpContent, bool>(property); } }
/// <summary> /// 属性描述 /// </summary> /// <param name="property">属性信息</param> public PropertyDescriptor(PropertyInfo property) { this.Name = property.Name; this.Info = property; if (property.CanRead == true) { this.geter = LambdaUtil.CreateGetFunc <TDeclaring, TProperty>(property); } if (property.CanWrite == true) { this.seter = LambdaUtil.CreateSetAction <TDeclaring, TProperty>(property); } }
public void GetTest() { var model = new Model { name = "laojiu" }; var p = model.GetType().GetProperty("name"); var getter = LambdaUtil.CreateGetFunc <Model, string>(p); var name = getter.Invoke(model); Assert.True(name == model.name); var getter2 = LambdaUtil.CreateGetFunc <object, string>(p); var name2 = getter2.Invoke(model); Assert.True(name2 == model.name); var getter3 = LambdaUtil.CreateGetFunc <object, object>(p.DeclaringType, p.Name); var name3 = getter2.Invoke(model).ToString(); Assert.True(name3 == model.name); var kv = new KeyValuePair <string, int>("k", 10); var getter4 = LambdaUtil.CreateGetFunc <object, object>(kv.GetType(), "Value"); var value = (int)getter4.Invoke(kv); Assert.True(value == kv.Value); var getter5 = LambdaUtil.CreateGetFunc <object, int>(kv.GetType(), "Value"); Assert.True(getter5.Invoke(kv) == kv.Value); var getter6 = LambdaUtil.CreateGetFunc <object, long>(kv.GetType(), "Value"); Assert.True(getter6.Invoke(kv) == kv.Value); }