C#属性的用法:只允许使用特定数据类型的属性的属性 [英] C# attribute usage: only allow attributes on a property with specific data type

查看:88
本文介绍了C#属性的用法:只允许使用特定数据类型的属性的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为性能的一些属性。现在我想用特定的数据类型限制这些属性的属性?这个想法是,如果它被分配到不同类型的编译器错误将被抛出。这可能吗?

I've created a few attributes for properties. now I want to limit these attributes to properties with a certain data type? the idea is, a compiler error will be thrown if it is assign to a different type. is this possible?

如果没有,那么我想我得检查它的运行时间。

if not, then I guess i'll have to check it on runtime.

推荐答案

您可以编写一个自定义的的FxCop /代码分析规则,以检查这一点。

You could write a custom FxCop/ Code Analysis rule to check for this.

的FxCop集成在VS 2010名代码Analyis下,您可以更改规则集在项目属性。

FxCop is integrated in VS 2010 under the name "Code Analyis", you can change the ruleset in the project properties.

这篇关于C#属性的用法:只允许使用特定数据类型的属性的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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