title: Get Data Annotations attributes from model
body: <p>I want to create custom client-side validator, but I want define validation rules via Data Annotations attributes at business logic layer. How can I access model validation attributes in runtime? </p>
  
  <p>I want to write 'generator', which will convert this code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class LoginModel
  {
      [Required]
      [MinLength(3)]
      public string UserName { get; set; }
  
      [Required]
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>into this one:</p>
  
  <pre class="lang-js prettyprint-override"><code>var loginViewModel= {
      UserName: ko.observable().extend({ minLength: 3, required: true }),
      Password: ko.observable().extend({ required: true })
  };
  </code></pre>
  
  <p>But not from .cs sources, of course. =)</p>
  
  <p>Maybe reflection?</p>
  
  <p><strong>UPD</strong></p>
  
  <p>I've found this method: <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.getunobtrusivevalidationattributes%28v=vs.108%29.aspx" rel="noreferrer">MSDN</a>. But can't understand how to use it.</p>