Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When are Attribute Objects created?

Tags:

c#

attributes

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?

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

like image 686
Dan Avatar asked Feb 06 '12 20:02

Dan


People also ask

What is an attribute object?

An attribute object is usually contained in Entry objects. An attribute is a named object with associated values. Each value in the attribute corresponds to a Java object of some type. Attribute names are not case-sensitive, and cannot contain a slash ( / ) as part of the name.

What are the attributes of objects called?

Variables that belong to an object are usually called attributes, but you might also see them called “fields”.

What are attributes of an object in Python?

An instance/object attribute is a variable that belongs to one (and only one) object. Every instance of a class points to its own attributes variables. These attributes are defined within the __init__ constructor.


1 Answers

From CLR via C#, third edition:

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.

like image 88
Smi Avatar answered Oct 06 '22 08:10

Smi