属性可以用C#动态添加? [英] Can attributes be added dynamically in C#?

查看:152
本文介绍了属性可以用C#动态添加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在运行时添加的属性或在运行时改变属性的值?

Is it possible to add attributes at runtime or to change the value of an attribute at runtime?

推荐答案

属性是静态的元数据。组件,模块,类型,成员,参数和返回值是在C#中没有第一类对象(如的System.Type类是一类仅仅是一个反映再presentation)。你可以得到一种类型的属性的一个实例,并改变它的性质,如果它们是可写的,但是,这将不影响属性,因为它是应用到该类型

Attributes are static metadata. Assemblies, modules, types, members, parameters, and return values aren't first-class objects in C# (e.g., the System.Type class is merely a reflected representation of a type). You can get an instance of an attribute for a type and change the properties if they're writable but that won't affect the attribute as it is applied to the type.

这篇关于属性可以用C#动态添加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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