title: How do I set a DefaultValue of a list property?
body: <p>I have a Helper class as such:</p>
  
  <pre><code>class Helper : Settings
  {
      [Setting, DefaultValue(false)]
      public bool DeclineData { get; set; }
  
      // ....
  
      [Setting, DefaultValue(new List&lt;string&gt;())]
      public List&lt;string&gt; AcceptList { get; set; }
  }
  </code></pre>
  
  <p>However my <code>DefaultValue</code> for <code>List&lt;string&gt;</code> results in error:</p>
  
  <blockquote>
    <p>An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type</p>
  </blockquote>
  
  <p>I've also tried <code>typeof(List&lt;string&gt;)</code> which also failed.</p>
  
  <p><code>Setting</code> is actually <code>System.Attribute</code> as <code>Settings</code> inherits from it, that's not my call as its not my code or open to changes.</p>
  
  <p>My question is, <strong>how can I set a <code>DefaultValue</code> to my property <code>AcceptList</code>?</strong></p>
  
  <hr>
  
  <p>While Selman22 answer does not generate a direct error to set the default value, it doesn't let it serialize or deserialize the data and since I am very limited in the information about this obfuscatated API I followed a different route.</p>
  
  <p>This is not a direct solution but rather an workaround until I figure out more information about this API, by setting my <code>DefaultValue("")</code> to empty and using my property as string with a delimiter to convert back and forth from a string to a list within a private property I was able to save the data I needed to.</p>