動的な式を作成し、それにラムダを割り当てようとしています。その結果、例外が発生しました:System.ArgumentException:タイプ'Test.ItsTrue'の式をタイプ'System.Linq.Expressions.Expression`1[Test.ItsTrue]'への割り当てに使用できません
なにが問題ですか?
public delegate bool ItsTrue();
public class Sample
{
public Expression<ItsTrue> ItsTrue { get; set; }
}
[TestClass]
public class MyTest
{
[TestMethod]
public void TestPropertySetWithExpressionOfDelegate()
{
Expression<ItsTrue> itsTrue = () => true;
// this works at compile time
new Sample().ItsTrue = itsTrue;
// this does not work ad runtime
var new_ = Expression.New(typeof (Sample));
var result = Expression.Assign(
Expression.Property(new_, typeof (Sample).GetProperties()[0]),
itsTrue);
}
}