title: YamlDotNet and custom types
body: <p>I am discovering yaml and yamldotnet. Sorry if this is a pretty basic question:</p>
  
  <ul>
  <li><p>does it make any sense to define user-defined types in yaml using the single exclamation mark such as:</p>
  
  <p>red: !color { red: 255, green: 0, blue: 0 }</p></li>
  <li><p>How is this deserialized by YamlDotNet? In other words is there a way to ensure that the type color is mapped to a corresponding Color type in .net?</p></li>
  <li><p>From my understanding of the following example <a href="https://dotnetfiddle.net/HD2JXM" rel="nofollow noreferrer">https://dotnetfiddle.net/HD2JXM</a>, YamlDotNet uses an implicit correspondence between the yaml document and the .net class  to map yaml properties the corresponding class properties (as shown in the example, this can be customized with annotations). However no type checking is done.</p></li>
  </ul>
  
  <p>To further clarify things. I have the following yaml document, which corresponds to a set of widgets:</p>
  
  <pre><code>controls:
    - Button:
        id: 1
        text: Hello Button World
    - Label:
        id: 2
        text: Hello Label World
    - TextView:
        id: 3
        content: &gt;
          This is some sample text that will appear
          in a text view.
  </code></pre>
  
  <p>And I want to map it to a corresponding type hierarchy in c#:</p>
  
  <pre><code>class AOPage
  {
      public IList&lt;AOControl&gt; Controls { get; set; }
  
  }
  
  class AOControl 
  {
      public int Id { get; set;}
  }
  
  class AOLabel : AOControl
  {
      public String Text { get; set;}
  }
  
  class AOButton : AOControl
  {
      public String Text { get; set;}
  }
  
  class AOTextView : AOControl
  {
      public String Contents{ get; set;}
  }
  </code></pre>
  
  <p>Note that there is a similar question poster here: <a href="https://stackoverflow.com/questions/23181376/using-custom-type-resolver-in-yamldotnet">Using custom type resolver</a>, which has not been answered.</p>
  
  <p>Thanks! </p>