title: Adding Editor / EditorAttribute at Run-time (Dynamically) to an Object's Property
body: <p><strong>How to add the EditorAttribute (Editor) to an object's property at run-time?</strong></p>
  <p>I have <code>My.Settings.ExcludeFiles</code>, which is created by the settings designer as <code>Public Property ExcludedFiles() As Global.System.Collections.Specialized.StringCollection</code>. When editing <code>ExcludedFiles</code> via a property grid, the &quot;String Collection Editor&quot; generates a &quot;Constructor on type 'System.String' not found&quot; run-time exception.</p>
  <p>I cannot change the attributes of the <code>ExcludeFiles</code> property because they will be overwritten the next time any setting changes are made. Therefore, I must attach/add the Editor/EditorAttribute at run-time.</p>
  <p>What I want to do is add the <code>StringCollectionEditor</code> at run-time, shown below as design-time attribute.</p>
  <pre><code>    &lt;Editor(GetType(StringCollectionEditor), GetType(UITypeEditor))&gt; _
  </code></pre>
  <hr />
  <h2>Solutions</h2>
  <h3>Method #1</h3>
  <pre><code>TypeDescriptor.AddAttributes( _
      GetType(Specialized.StringCollection), _
      New EditorAttribute( _
          &quot;System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;, _
           GetType(System.Drawing.Design.UITypeEditor)))
  </code></pre>
  <p>You only have to add this attribute once, such as application initialization.</p>
  <h3>Method #2</h3>
  <p>More flexible. See Nicolas Cadilhac
  answer below at <a href="https://stackoverflow.com/questions/2043579/adding-editor-editorattribute-at-run-time-dynamically-to-an-objects-property/2044673#2044673">Adding Editor / EditorAttribute at Run-time (Dynamically) to an Object&#39;s Property</a>. It uses derived  CustomTypeDescriptor and TypeDescriptionProvider classes. You only have to add the provider once, such as application initialization.</p>