title: Why can't I pass a property or indexer as a ref parameter when .NET reflector shows that it's done in the .NET Framework?
body: <p>Okay, I will cut and paste from .NET reflector to demonstrate what I'm trying to do:</p>
  
  <pre><code>public override void UpdateUser(MembershipUser user)
  {
      //A bunch of irrelevant code...
  
      SecUtility.CheckParameter(ref user.UserName, true, true, true, 0x100, "UserName");
  
      //More irrelevant code...
  }
  </code></pre>
  
  <p>This line of code comes right out of System.Web.Security.SqlMembershipProvider.UpdateUser (System.Web.dll v2.0.50727) in the .NET Framework.</p>
  
  <p>The SecUtility.CheckParameter requires a reference value as the first parameter, to which they're passing a property of the user passed in as the argument.</p>
  
  <p>The definition of the CheckParameter code is:</p>
  
  <pre><code>internal static void CheckParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName)
  {
      //Code omitted for brevity
  }
  </code></pre>
  
  <p>Everything it's doing makes sense - on paper... so I knock up a quick little prototype for somewhere I'd like to use something similar:</p>
  
  <pre><code>public class DummyClass
  {
      public string ClassName{ get; set; }
  }
  
  public class Program
  {
      private static DoSomething(ref string value)
      {
          //Do something with the value passed in
      }
  
      public static Main(string[] args)
      {
          DummyClass x = new DummyClass() { ClassName = "Hello World" };
  
          DoSomething(ref x.ClassName); //This line has a red squiggly underline 
                                        //under x.ClassName indicating the 
                                        //error provided below.
      }
  }
  </code></pre>
  
  <p>This code won't compile - the error shows as:</p>
  
  <pre><code>"A property or indexer may not be passed as an out or ref parameter"
  </code></pre>
  
  <p>Fair enough... but why won't my code allow me to do something that appears to be in the .NET Framework code base?  Is this an error with the way .NET Reflector is interpreting the DLL or is this an error with the way I'm interpreting their code?</p>