【问题标题】:Blocking event subscription in compile time在编译时阻塞事件订阅
【发布时间】:2010-02-18 09:31:44
【问题描述】:

my previous question 相关。有没有办法在编译时阻止订阅?类似于在实现器中将事件的“添加”标记为“私有”,即使它在接口中是公开的。

【问题讨论】:

    标签: c# events blocking subscriber


    【解决方案1】:

    您可以定义编译宏,并环绕#if 标记。

    #if DEBUG
    // do something only when we are launching Debug configuration
    #endif
    
    #if MYMACRO
    // do something only when this macro is defined
    #endif
    

    【讨论】:

    • 我不明白这是如何回答我的问题的。
    • 如果您告诉编译器在编译时省略,您可以在编译时阻止订阅。为此,您使用#if 块,并使用宏。这样,如果您正确设置#if,则其中的代码将不会在 exe 中编译,因为它从未在那里编写过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多