C#标记不完整的类,以便不进行编译? [英] C# Mark incomplete class so that it doesn't get compiled?

查看:142
本文介绍了C#标记不完整的类,以便不进行编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被告知您可以标记零件完整类,以便在编译其余完整代码时不会出现任何错误.

任何人都知道这是真的,如果是的话,该怎么做?

谢谢,

Jib

I''ve been told that you can mark a part complete class so that it doesn''t kick any errors when you compile the rest of the complete code.

Anyone know if this is true, and if so, how to do this?

Thanks,

Jib

推荐答案

您可以在代码中放置一个编译器指令(在包含该类的文件的顶部)

You could put a compiler directive in your code (at the top of the file containing the class)

#define __INCOMPLETE__

using ...;
using ...;

namespace ...
{
    public class My Class
    {
        public void MyMethod()
        {
#if (!__INCOMPLETE__)
            // put some code here
#endif
        }
    }
}


我也从未听说过.

但是您可以使用#if指令隐藏"代码的一部分,但是在这部分中将无法使用智能感知.这通常用于添加一些调试特定的代码.例如:

I''ve never heard of that either.

But you can use #if directive to "hide" a part of your code but then intellisense will not be available in that part. This is often used to add some debug specific code. For example:

    //your normal code here
    ...
#if DEBUG
    //do something special for your debug mode
    //this part will be compiled only in debug mode
    //if you are in Release, then intellisense will not be available in this part
    ... 
#endif
    //rest of your normal code
    ...



如果愿意,还可以将其强制为false:



You can also force it to false if you wish:

    //your normal code here
    ...
#if false
    //this part will never be compiled
    //intellisense will not be available in this part unless you change false to true
    ...
#endif
    //rest of your normal code
    ...


这篇关于C#标记不完整的类,以便不进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆