Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object creation in C# question

I'm going over some c# tutorial that states the following:

"After it finds the attribute class, the compiler will check whether the attribute is allowed on a class. Then it will check for a constructor that matches the parameters specified in the attribute use. If it finds one, it creates an instance of the object by calling the constructor with the specified values"

The name of this paragraph is "compilation process", and it refers to the way the compiler handles attributes. I'm sorry for the ignorance, but shouldn't instances be created at run time?

Thanks.

like image 449
user429400 Avatar asked Nov 21 '10 16:11

user429400


2 Answers

Attributes define metadata for classes -- every instance of the class (i.e. object) will share the same attribute values. This metadata is stored alongside the type definition, which is calculated once at compile time from the source files.

like image 190
Rowland Shaw Avatar answered Sep 30 '22 16:09

Rowland Shaw


Since there are attributes that also affect the compiler, I wouldn't be surprised if the compiler did instantiate them when compiling. So what?

like image 20
Vilx- Avatar answered Sep 30 '22 16:09

Vilx-