How to use variable in property (attribute)
-
I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW
-
I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW
You can declare constants and use those in your attributes, but not variables. Since attributes are metadata, the values must be defined at compile-time, not at runtime.
Microsoft MVP, Visual C# My Articles
-
I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW
Just overload the constructor, very handy with attributes. Remember attributes are readonly because they are stored in metadata, and hence, can be changed at runtime.
-
I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW
Thx for all Hi, AW