编程属性添加到方法或参数 [英] Programmatically add an attribute to a method or parameter

查看:156
本文介绍了编程属性添加到方法或参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用TypeDescriptor.AddAttributes一个属性添加到运行时类型。我该怎么做的方法和参数是否相同? (也许2个独立的问题...)

I can use TypeDescriptor.AddAttributes to add an attribute to a type in runtime. How do I do the same for a method and parameter? (maybe 2 separate questions...)

推荐答案

TypeDescriptor.AddAttributes 只影响的非常的具体使用情况;即从内部 System.ComponentModel 。对于的其他的反思,它知道的没有的有关额外的属性。事实上, System.ComponentModel 并没有真正适用于方法和参数。

TypeDescriptor.AddAttributes only affects a very specific use-case; i.e. from within System.ComponentModel. For the rest of reflection, it knows nothing about the extra attribute. And indeed, System.ComponentModel doesn't really apply to methods or parameters.

因此​​,在短期;你不能。您将需要存储这些信息在其他地方(显出),或在编译时添加。

So in short; you can't. You will need to store this information somewhere else (bespoke), or add it at compile-time.

这篇关于编程属性添加到方法或参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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