草庐IT

MemberExpression

全部标签

c# - 无法将类型为 'System.Linq.Expressions.UnaryExpression' 的对象转换为类型 'System.Linq.Expressions.MemberExpression'

我创建了一个methodinC#获取方法名publicstringGetCorrectPropertyName(Expression>expression){return((MemberExpression)expression.Body).Member.Name;//FailurePoint}并将其称为stringlcl_name=false;publicstringName{get{returnlcl_name;}set{lcl_name=value;OnPropertyChanged(GetCorrectPropertyName(x=>x.Name));}}如果属性是字符串并且对

c# - 从 MemberExpression 中获取对象?

所以,假设我在C#中有以下表达式:Expression>expr=()=>foo.Bar;如何提取对foo的引用? 最佳答案 Ihadthesameproblem,butsomewhatmorecomplex,andDarinDimitrov'sanswergavemeagoodstart.I'llpostmyresultshere,despitethefactthatthisisan"old"question.情况一:根对象是实例成员this.textBox.Text//where'this'hastype'Form'...等价于

c# - 类型成员的表达式导致不同的表达式(MemberExpression、UnaryExpression)

描述我有一个表达式指向我的类型的属性。但它不适用于所有属性类型。"不是意思"是什么意思它导致不同的表达类型。我以为它会导致MemberExpression但事实并非如此。对于int和Guid它产生一个UnaryExpression而对于string在MemberExpression中。我有点困惑;)一些示例代码我的类(class)publicclassPerson{publicstringName{get;set;}publicintAge{get;set;}}测试代码Personp=newPerson{Age=16,Name="John"};Expression>expression
12