Tôi nên xây dựng cây biểu thức cho string.IndexOf("substring", StringComparison.OrdinalIgnoreCase)
như thế nào?Cây biểu thức cho phương thức String.IndexOf
Tôi có thể làm cho nó hoạt động mà không có đối số thứ hai: StringComparison.OrdinalIgnoreCase
. Đây là những nỗ lực của tôi cho đến nay:
var methodCall = typeof (string).GetMethod("IndexOf", new[] {typeof (string)});
Expression[] parms = new Expression[]{right, Expression.Constant("StringComparison.OrdinalIgnoreCase", typeof (Enum))};
var exp = Expression.Call(left, methodCall, parms);
return exp;
Cũng cố gắng này:
var methodCall = typeof (string).GetMethod(method, new[] {typeof (string)});
Expression[] parms = new Expression[]{right, Expression.Parameter(typeof(Enum) , "StringComparison.OrdinalIgnoreCase")};
var exp = Expression.Call(left, methodCall, parms);
return exp;
Hãy nhớ rằng tôi có thể lấy nó làm việc nếu tôi bỏ qua các tham số OrdinalIgnoreCase
.
Cảm ơn
Như mọi khi, khi bạn có vấn đề bạn nên nói những gì đang xảy ra với những gì bạn đã thử - bạn có ngoại lệ, lỗi biên dịch, hành vi sai? Nếu đó là lỗi của một số loại, lỗi là gì? –
Xin lỗi. Tôi sẽ ghi nhớ điều đó trong lần tới khi đặt câu hỏi. Tôi đã nhận được một ArgumentException. – ashokgelal
Cần trợ giúp: [how-do-i-tạo-một-biểu-tree-to-đại diện-chuỗi-chứa-in-in] (http://stackoverflow.com/questions/278684/how-do-i-create- a-expression-tree-to-represent-string-containssterm-in-c) – nawfal