title: How do I add a method to a property?
body: <p>Let's say I create a class with a property:</p>
  
  <pre><code>public class User
  {
     private string _userID;
  
     public string UserID
     {
        get { return _userID; }
        set { _userID = value; }
     }
  }
  </code></pre>
  
  <p>What do I have to do with the class and property to be able to have a method attached to the UserID property, such as a method that generates Xml around the user ID with the "dot" syntax:</p>
  
  <pre><code>User u = new User();
  u.UserID = "Mike";
  string xml = u.UserID.ToXml();
  </code></pre>
  
  <p>I can figure out how to write a method to put Xml tags around the value of the UserID, the part that is eluding me is how to make the method work with the property using the "dot" syntax.</p>
  
  <hr>
  
  <p>All of these answers are useful, and thanks to everyone for contributing.  In fact, the answer I marked as "accepted" was precisely what I was looking for.  I appreciate the cautionary remakrs on extension methods (which I had never heard of before this), and of course it could be a problem to apply the extension method to all strings in some circumstances, but in this case I definitely wanted to apply the method ToXml() to all string properties in the class.  Just what the doctor ordered.  I am quite familiar with XmlSerialization, but in this case needed to avoid it for various reasons.  </p>