に私は昨日から式ツリー自分自身を教えてきたと私は2つの文字列値を比較する問題を抱えています。私はエラーで失敗し、このテストケースを作った:使用string.Compare(a、b)は式
No method 'Compare' on type 'System.String' is compatible with the supplied arguments.
は、私がExpression.Equal, LessThan, LessThanOrEqual, GreaterThan or GreaterThanOrEqual
その結果、左&右を使用しますleft = Expression.Call(
Type type = typeof(string);
Expression left, right;
left = Expression.Constant("1", type);
right = Expression.Constant("2", type);
// fails at run-time on the next statement
left = Expression.Call(
typeof(string),
"Compare",
new Type[] { type, type },
new Expression[] { left, right });
right = Expression.Constant(0, typeof(int));
上で実行時に失敗します。これがCompareメソッドの理由です。
私はその何かがシンプル確信している、と私はこの単純なテストケースに私のコードを煮詰めてきました。誰かが私が間違っているのを見た? - 彼らはジェネリック引数、ではない通常のパラメータのタイプだ
new Type[] { type, type },
string.Compare<string, string>
を呼び出すようにしようとしている: