Assign a value from App.Config to a Attribute of a Property

Dec 21 2018 9:57 AM

We want to set a attribute value from app.config and using following code, it gives error

"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type"

  1. public class A  
  2. {  
  3.         [JsonProperty(ConfigurationManager.AppSettings["Application:ExplicitUserTypeAttribute"]]  
  4.         public string ExplicitUserTypeAttribute { getset; }  
  5. }  

 

I understand this has to be a constant that can be computed at compile time but this is our requirement and I'm wondering if there is any work around to get it working.

Thanks!


Answers (2)