0

I want to initialize the class attributes from the configuration file such as:

    [LuisModel(modelID: ConfigurationManager.AppSettings["LUISAppId"], subscriptionKey: ConfigurationManager.AppSettings["LUISSubscription"], domain: ConfigurationManager.AppSettings["LUISDomain"])]
    [Serializable]
    public class NoteDialog : LuisDialog<object>
    {
    }

but I get the following error:

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

Any idea if the class attributes can be read from a config file?

KeykoYume
  • 2,497
  • 6
  • 24
  • 48
  • 2
    The settings within the file are a runtime-information. Attributes on the other hand are compile-time information. Thus what you want is not possible. – MakePeaceGreatAgain Dec 05 '17 at 09:22
  • 1
    Technically you can change the values of the Instances of the attributes at runtime for example by: using typeof(MyClass).GetCustomAttributes to get them and changing properties on them. – MarkovskI Dec 05 '17 at 09:59

0 Answers0