title: Is it possible to get a property's private setter through reflection?
body: <p>I wrote a custom serializer that works by setting object properties by reflection. Serializable classes are tagged with serializable attribute and all serializable properties are also tagged. For example, the following class is serializable:</p>
  
  <pre><code>[Serializable]
  public class Foo
  {
     [SerializableProperty]
     public string SomethingSerializable {get; set;}
  
     public string SometthingNotSerializable {get; set;}
  }
  </code></pre>
  
  <p>When the serializer is asked to deserialize <code>SomethingSerializable</code>, it gets the set method of the property and uses it to set it by doing something like this:</p>
  
  <pre><code>PropertyInfo propertyInfo; //the property info of the property to set
  //...//
  if (propertyInfo.CanWrite &amp;&amp; propertyInfo.GetSetMethod() != null)
  {
     propertyInfo.GetSetMethod().Invoke(obj, new object[]{val});
  }
  </code></pre>
  
  <p>This works fine, however, how can I make the property setter accessible only to the serializer? If the setter is private:</p>
  
  <pre><code>public string SomethingSerializable {get; private set;}
  </code></pre>
  
  <p>then the call to <code>propertyInfo.GetSetMethod()</code> returns null in the serializer. Is there any way to access the private setter or any other way to ensure that only the serializer can access the setter? The serializer is not guaranteed to be in the same assembly. </p>