❔ CSharp [] attribute help
Hi! sorry for the basic question, but I need a not so technical and more casual explanation about (I think it is) the call of attributes through brackets []
Like this code:
5 Replies
Those are attributes, they don't call anything
They're just metadata that other code can use
Ah
Thanks you
While I generally agree with this, we have a ton of code in some attributes we define that gets executed via the attribute constructor and calls all sorts of other code to set up a bunch of data structures, etc.
This is invoked when GetCustomAttribute is used to retrieve the attribute metadata.
So depending on the code base, there can be a lot of code lurking inside attributes...it's just not executed until someone uses reflection to retrieve the attribute on something.
I might've not been clear enough, yeah, I agree. What I meant is that just adding an attribute to a thing doesn't do anything on its own. Attributes can contain code, but something else needs to call that code.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.