/// <summary> /// 尝试将集合转换为单值集合 /// </summary> /// <param name="values"></param> /// <returns></returns> public bool TryGetSingleValues(out PrimitiveValueList values) { values = null; if (ItemIsSingleValue()) { values = new PrimitiveValueList(this.Select((v) => v.GetValue())); return(true); } return(false); }
/// <summary> /// 实现动态对象属性成员访问的方法,得到返回指定属性的值 /// </summary> /// <param name="binder"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryGetMember(GetMemberBinder binder, out object result) { result = GetValue(binder.Name, false); var objs = result as DTObjects; PrimitiveValueList values = null; if (objs != null && objs.TryGetSingleValues(out values)) { result = values; } //return result != null; return(true); //无论什么情况下都返回true,表示就算dto没有定义值,也可以获取null }