有没有办法建立Expression<Func<T,bool>>起来Expression<Func<T>>?
比如上课
public class MyClass
{
public int Prop1{get;set;}
public int Prop2{get;set;}
public int Prop3{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
如果Expression<Func<T>>是() => new MyClass{Prop2 = 5}那么结果应该是x => x.Prop2 == 5
如果Expression<Func<T>>是() => new MyClass{Prop1 = 1, Prop3 = 3}那么结果应该是x => x.Prop1 == 1 && x.Prop3 == 3
换句话说,是否可以在运行时创建具有任意数量条件的func?
我需要获取 asp.net MVC 的请求处理时间。我使用 IHttpModule 订阅 onBeginRequest 和 onEndRequest 事件。对于同步控制器,它工作得很好,但对于异步,它返回错误的结果(例如,当实时时间约为 2 分钟时为 20 毫秒)。如何以一般方式获得 AsyncController 的请求处理时间(不在 ActionAsync/ActionCompleted 中为每个异步操作编写附加代码)?
public class TrackRequestModule : RequestProcessingModuleBase, IHttpModule
{
public const string BeginRequestTimeKey = "beginRequestTime";
public void Init(HttpApplication context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.BeginRequest += onBeginRequest;
context.EndRequest += onEndRequest;
}
private void onEndRequest(object sender, EventArgs e)
{
InvokeHandler(sender, OnEndRequest);
}
private void onBeginRequest(object sender, EventArgs e)
{
InvokeHandler(sender, OnBeginRequest);
}
public void OnBeginRequest(HttpContextBase context)
{
context.Items[BeginRequestTimeKey] = DateTime.Now.ToLocalTime(); …Run Code Online (Sandbox Code Playgroud)