在C#中跳过方法调用?

时间:2022-04-28 20:48:58

I have this simple code :

我有这个简单的代码:

 void Application_BeginRequest(object sender, EventArgs e) 
    {
        Trace.Write("Exception Handling", "......");
    }

However re-sharper scream (no-error only suggest) about :

然而,重新锐利的尖叫(无错误仅建议):

在C#中跳过方法调用?

Method invocation is skipped. Compiler will not generate method invocation because the method is conditional, or it is a partial method without implementation

跳过方法调用。编译器不会生成方法调用,因为该方法是有条件的,或者它是没有实现的部分方法

I'm not able to see this line in the Trace output.

我无法在Trace输出中看到此行。

however - other traces - I do see.

然而 - 其他痕迹 - 我确实看到了。

Why is that ?

这是为什么 ?

(p.s. The page (which is under web Site project) has trace="true").

(p.s.页面(在网站项目下)有trace =“true”)。

2 个解决方案

#1


19  

Be sure that the TRACE constant is defined in your project settings for your current build configuration.

确保在当前构建配置的项目设置中定义了TRACE常量。

在C#中跳过方法调用?

UPDATE

Since it's a website project, you could put

既然这是一个网站项目,你可以放

#define TRACE

at the top of Global.asax.cs so that the trace symbol is defined.

在Global.asax.cs的顶部,以便定义跟踪符号。

#2


2  

To quote the JetBrains wiki (which may* be linked to from the ReSharper menu under 'Why is ReSharper suggesting this'):

引用JetBrains wiki(可以从“为什么ReSharper建议这个”下的ReSharper菜单链接到):

While coding, you may encounter warnings regarding methods whose invocations will not be generated by the compiler. Why would that be? Typical cases are conditional methods that will not be compiled (e.g., it’s marked with [ReSharperInt:Conditional("DEBUG")] and you’re in RELEASE mode). Another reason why a method may be skipped is that, at some point, its body has been declared as partial and the implementation wasn’t provided.

编码时,您可能会遇到有关编译器不会调用其调用的方法的警告。那为什么会这样?典型情况是不会被编译的条件方法(例如,它用[ReSharperInt:Conditional(“DEBUG”)标记]并且您处于RELEASE模式。可以跳过方法的另一个原因是,在某些时候,它的主体已被声明为部分并且未提供实现。

Given that this is on a method of Trace, I'd suggest the first of these typical cases is the one that applies.

鉴于这是Trace的方法,我建议这些典型案例中的第一个是适用的案例。

* I haven't got v7 yet

*我还没有v7

#1


19  

Be sure that the TRACE constant is defined in your project settings for your current build configuration.

确保在当前构建配置的项目设置中定义了TRACE常量。

在C#中跳过方法调用?

UPDATE

Since it's a website project, you could put

既然这是一个网站项目,你可以放

#define TRACE

at the top of Global.asax.cs so that the trace symbol is defined.

在Global.asax.cs的顶部,以便定义跟踪符号。

#2


2  

To quote the JetBrains wiki (which may* be linked to from the ReSharper menu under 'Why is ReSharper suggesting this'):

引用JetBrains wiki(可以从“为什么ReSharper建议这个”下的ReSharper菜单链接到):

While coding, you may encounter warnings regarding methods whose invocations will not be generated by the compiler. Why would that be? Typical cases are conditional methods that will not be compiled (e.g., it’s marked with [ReSharperInt:Conditional("DEBUG")] and you’re in RELEASE mode). Another reason why a method may be skipped is that, at some point, its body has been declared as partial and the implementation wasn’t provided.

编码时,您可能会遇到有关编译器不会调用其调用的方法的警告。那为什么会这样?典型情况是不会被编译的条件方法(例如,它用[ReSharperInt:Conditional(“DEBUG”)标记]并且您处于RELEASE模式。可以跳过方法的另一个原因是,在某些时候,它的主体已被声明为部分并且未提供实现。

Given that this is on a method of Trace, I'd suggest the first of these typical cases is the one that applies.

鉴于这是Trace的方法,我建议这些典型案例中的第一个是适用的案例。

* I haven't got v7 yet

*我还没有v7