<i id='D4f4W'><tr id='D4f4W'><dt id='D4f4W'><q id='D4f4W'><span id='D4f4W'><b id='D4f4W'><form id='D4f4W'><ins id='D4f4W'></ins><ul id='D4f4W'></ul><sub id='D4f4W'></sub></form><legend id='D4f4W'></legend><bdo id='D4f4W'><pre id='D4f4W'><center id='D4f4W'></center></pre></bdo></b><th id='D4f4W'></th></span></q></dt></tr></i><div id='D4f4W'><tfoot id='D4f4W'></tfoot><dl id='D4f4W'><fieldset id='D4f4W'></fieldset></dl></div>
    • <bdo id='D4f4W'></bdo><ul id='D4f4W'></ul>

      <tfoot id='D4f4W'></tfoot>
    1. <small id='D4f4W'></small><noframes id='D4f4W'>

      1. <legend id='D4f4W'><style id='D4f4W'><dir id='D4f4W'><q id='D4f4W'></q></dir></style></legend>

        生成自定义编译时警告 C#

        时间:2023-10-06

          <i id='wzlZg'><tr id='wzlZg'><dt id='wzlZg'><q id='wzlZg'><span id='wzlZg'><b id='wzlZg'><form id='wzlZg'><ins id='wzlZg'></ins><ul id='wzlZg'></ul><sub id='wzlZg'></sub></form><legend id='wzlZg'></legend><bdo id='wzlZg'><pre id='wzlZg'><center id='wzlZg'></center></pre></bdo></b><th id='wzlZg'></th></span></q></dt></tr></i><div id='wzlZg'><tfoot id='wzlZg'></tfoot><dl id='wzlZg'><fieldset id='wzlZg'></fieldset></dl></div>
            • <bdo id='wzlZg'></bdo><ul id='wzlZg'></ul>
              • <small id='wzlZg'></small><noframes id='wzlZg'>

              • <tfoot id='wzlZg'></tfoot>

                <legend id='wzlZg'><style id='wzlZg'><dir id='wzlZg'><q id='wzlZg'></q></dir></style></legend>

                    <tbody id='wzlZg'></tbody>
                  本文介绍了生成自定义编译时警告 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 VS2008,并希望根据属性的自定义属性创建编译时警告/错误(如果可能的话).

                  I'm using VS2008 and would like to create a compile time warning / error based on custom attributes on a property (if it is possible).

                  目前我感兴趣的有两种情况:

                  There are two cases which interest me currently:

                    [MyAttribute (typeof(MyClass)]
                  

                  MyClass 必须实现一个接口.目前我在属性的构造函数中声明了这一点,但是由于堆栈跟踪的性质,这并不容易追踪:

                  Where MyClass has to implement an interface. Currently I assert this in the constructor of the attribute, however this doesn't make it easy to track down, due to the nature of the stack trace:

                   public MyAttribute (Type MyClassType)
                      {
                           System.Diagnostics.Debug.Assert(typeof(MyInterface).IsAssignableFrom(MyClassType),
                                                           "Editor must implement interface: " + typeof(MyInterface).Name);
                  
                      }
                  

                  我感兴趣的第二种情况是我在属性中定义了一个类型,如果该类型实现了一个接口,那么如果另一个属性不存在,则应该显示警告.

                  The second case which interests me is where I have a type defined in an attribute, if that type implements an interface, then a warning should be displayed if another attribute isn't present.

                  I.E.if (MyClass.Implements(SomeInterface) && !Exists(SomeAttibute)) { 生成警告 }

                  I.E. if (MyClass.Implements(SomeInterface) && !Exists(SomeAttibute)) { Generate Warning }

                  [MyAttribute(typeof(MyClass)] 
                  // Comment next line to generate warning
                  [Foo ("Bar")]
                  

                  谢谢!

                  推荐答案

                  您可以使用 PostSharp 做到这一点.

                  You can do that with PostSharp.

                  我曾经做过,并解释了如何做 这里

                  I've once done it, and explained how to do it here

                  这篇关于生成自定义编译时警告 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“无法评估表达式,因为当前方法的代码已优化."是什么意思?意思是? 下一篇:C# 编译器或 JIT 在什么级别优化应用程序代码?

                  相关文章

                    <small id='e89Rq'></small><noframes id='e89Rq'>

                  1. <tfoot id='e89Rq'></tfoot>
                    <legend id='e89Rq'><style id='e89Rq'><dir id='e89Rq'><q id='e89Rq'></q></dir></style></legend>

                    <i id='e89Rq'><tr id='e89Rq'><dt id='e89Rq'><q id='e89Rq'><span id='e89Rq'><b id='e89Rq'><form id='e89Rq'><ins id='e89Rq'></ins><ul id='e89Rq'></ul><sub id='e89Rq'></sub></form><legend id='e89Rq'></legend><bdo id='e89Rq'><pre id='e89Rq'><center id='e89Rq'></center></pre></bdo></b><th id='e89Rq'></th></span></q></dt></tr></i><div id='e89Rq'><tfoot id='e89Rq'></tfoot><dl id='e89Rq'><fieldset id='e89Rq'></fieldset></dl></div>
                      • <bdo id='e89Rq'></bdo><ul id='e89Rq'></ul>