【问题标题】:Is there an attribute that is effectively the opposite of ObsoleteAttribute?是否存在与 ObsoleteAttribute 相反的属性?
【发布时间】:2015-10-01 17:44:08
【问题描述】:

换句话说,是否有一个Attribute 将一段代码标记为不是太,而是太,因此还没有准备好广泛使用?

如果我必须创建一个自定义 Attribute 来完成此操作,那很好。我只是想先确定一下。

【问题讨论】:

标签: c# attributes


【解决方案1】:

不,这方面没有任何标准化。您可能需要考虑不公开这样的代码 - 或者只在 beta 版本等中公开它。

【讨论】:

    【解决方案2】:

    不是属性,但有预处理指令 (https://msdn.microsoft.com/en-us/library/ed8yd1ha.aspx),我们可以使用它们将代码区域标记为“太新”而无法运行。基本上你可以定义一个标志来表明这段代码已经准备好了。

    这是一个例子:

    #define FOREST_CAN_RUN
    //undef FOREST_CAN_RUN --> disable that feature
    using System;
    namespace Test
    {
        public class Forest
        {
            public void Run()
            {
    #if FOREST_CAN_RUN
                Console.Write("Run Forest, Run !");
    #else
                Console.Write("Sorry, Jenny");
    #endif
            }
        }
    
        public class Program
        {
            static void Main(string[] args)
            {
                Forest f= new Forest ();
                f.Run();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多