替代嵌套类型型防爆pression&LT的; Func键&LT; T&GT;&GT; [英] Alternative to nested type of type Expression<Func<T>>
问题描述
我有调用服务时使用的功能。之前,它调用服务,它会创建一个日志条目:
I have a function used when calling a service. Before it call the service, it will create a log entry:
protected TResult CallService<TService, TResult>(TService service,
Expression<Func<TService, TResult>> functionSelector)
{
Logger.LogServiceCall(service, functionSelector);
return functionSelector.Compile()(service);
}
在Visual Studio 2010 code分析仪告诉我,我不应该在下面留言使用嵌套类型:
The Visual Studio 2010 Code Analyzer informs me that I shouldn't use Nested Type in the following message:
CA1006:Microsoft.Design:考虑
设计中
ServiceManager.CallService&LT; TService,
结果&GT;(TService,
防爆pression&LT;&Func键LT; TService,TResult&GT;&GT;)
不窝泛型类型
前pression&LT;&Func键LT; TService,TResult&GT;&GT;
CA1006 : Microsoft.Design : Consider a design where 'ServiceManager.CallService<TService, Result>(TService, Expression<Func<TService, TResult>>)' doesn't nest generic type 'Expression<Func<TService, TResult>>'.
虽然我可以简单地创建此条目标SUP pression规则,是有存在,将prevent显示这样的警告的方法吗?
While I could simply create a suppression rule for this entry, is there is an alternative that exist that would prevent displaying such warning?
推荐答案
我想喝preSS它在这种情况下,其原因是,来电者不必应付嵌套泛型,他只是一个路过拉姆达前pression,它很容易使用。
I would suppress it in this case, with the reason that the caller doesn't have to cope with nested generics, he is just passing a lambda expression, which is easy to use.
CA不会使拉姆达前pressions例外。有时,这是更好地共进晚餐preSS它,然后写怪异code。
CA does not make exceptions for lambda expressions. Sometimes It is better to suppress it then to write weird code.
这篇关于替代嵌套类型型防爆pression&LT的; Func键&LT; T&GT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!