关于ConditionalAttribute

hityct1 2014-07-09 11:40:07

using System.Diagnostics;

namespace AttributeTest.Test
{
[Conditional("DEBUG")]
class Class1
{
}
}


为什么提示错误:特性“System.Diagnostics.ConditionalAttribute”仅对方法或特性类有效
但我看ConditionalAttribute有如下特性

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]

求解.
...全文
163 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hityct1 2016-05-09
  • 打赏
  • 举报
回复
[Conditional("DEBUG")]
public class Documentation : System.Attribute

看来是只能应用到继承System.Attribute类
hityct1 2014-07-09
  • 打赏
  • 举报
回复
可是Conditional的特性有 AttributeTargets.Class 呀
长期潜水、 2014-07-09
  • 打赏
  • 举报
回复
如果你硬要用
using System.Diagnostics;
 
namespace AttributeTest.Test
{
    [Conditional("DEBUG")]
    class Class1:System.Attribute
    {
    }
}
长期潜水、 2014-07-09
  • 打赏
  • 举报
回复
因为 “System.Diagnostics.ConditionalAttribute” 只对特性类或 void返回类型方法有效。
长期潜水、 2014-07-09
  • 打赏
  • 举报
回复
引用 3 楼 hityct1 的回复:
可是Conditional的特性有 AttributeTargets.Class 呀
Conditionnal是类库自带的。。。看MSDN解释http://msdn.microsoft.com/zh-cn/library/4xssyw96.aspx

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧