Creating an object in a C # question

I am moving on to some C # tutorial that says the following:

“After it finds the attribute class, the compiler checks to see if the attribute is allowed for the class. Then it checks the constructor that matches the parameters specified in the attribute use. If it finds it, it instantiates the object by calling the constructor with the specified values

The title of this paragraph is “compilation process”, and this refers to the way the compiler handles attributes. I apologize for not knowing, but don't need to instantiate at runtime?

Thanks.

+6
instantiation c #
source share
4 answers

Attributes define metadata for classes - each instance of a class (i.e., an object) will use the same attribute values. This metadata is stored along with a type definition that is computed once at compile time from source files.

+3
source share

Since there are attributes that also affect the compiler , I would not be surprised if the compiler did by creating them at compilation. So what?

+2
source share

There is a “compilation” process that generates intermediate code that is interpreted using the .NET framework.

That's why they talk about the compilation process.

+1
source share

The compiler creates only metadata that describes the construction of the attribute and the purpose of its properties. The attribute itself is only created when you use reflection to display the attributes of the list. I think that every reflection call creates a new instance of this attribute.

And I think that there is a way (related only to reflection contexts) to check an attribute directly from the meta without creating it at all.

0
source share

All Articles