如何在编译器中使用自定义属性 [英] How to use custom Attribute during complier

查看:74
本文介绍了如何在编译器中使用自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个自定义属性,例如

 [ClassNameLength( 2 )]
 public   class  HelloWorld 它可以验证类名的长度. 
但最重要的是,我想在构建项目时显示诸如Attribute AttributeUsage之类的长度错误.

请给我一些建议.

谢谢.

解决方案

由于要在编译过程中使用此属性,因此需要扩展Visual Studio http://www.binarycoder.net/fxcop/html/index.html [ ^ ]


Hi,

I have one custom Attribute like

[ClassNameLength(2)]
public class HelloWorld

It can validate the length of the class name.
But the most important of all, I want to show the length error like the Attribute AttributeUsage when building the project.

Please give me some advice.

Thank You.

解决方案

Since you want this Attribute to be used during compile you will need to extend Visual Studio Developing Visual Studio Extensions[^]

However, it may be more appropriate for you to create a custom FXCop rule.

http://www.binarycoder.net/fxcop/html/index.html[^]


这篇关于如何在编译器中使用自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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