当属性对象产生的? [英] When are Attribute Objects created?

查看:115
本文介绍了当属性对象产生的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于属性是真的只是附加的元数据集会,这是否意味着属性的对象只能按要求创建(当你调用GetCustomAttributes等)?

Since Attributes are really just Metadata attached to assemblies, does that mean that Attribute Objects are only created on request (such as when you call GetCustomAttributes)?

或者,他们在创建对象的创建?

Or are they created on creation of the object?

或者,前2的组合中,当对象被创建,由于由CLR归因扫描创建

Or, a combination of the first 2, created when the object is created due to attribute scanning by the CLR?

推荐答案

从CLR,第三版:

如果你想构建一个属性对象,必须调用 GetCustomAttributes
   GetCustomAttribute 。每次这些方法之一被调用时,它构造新的实例
  指定的属性类型,并设置每个实例的字段和属性的基础上在源$ C ​​$ C指定的值的。这些方法返回给应用属性类的完全构造实例的引用。

If you want to construct an attribute object, you must call either GetCustomAttributes or GetCustomAttribute. Every time one of these methods is called, it constructs new instances of the specified attribute type and sets each of the instance’s fields and properties based on the values specified in the source code. These methods return references to fully constructed instances of the applied attribute classes.

所以,是的,他们只是按要求创建。

So yes, they are only created on request.

这篇关于当属性对象产生的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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