title: GetType() can lie?
body: <p>Based on the following question asked a few days ago in SO: <a href="https://stackoverflow.com/questions/16679239/gettype-and-polymorphism">GetType() and polymorphism</a> and reading <a href="https://stackoverflow.com/questions/16679239/gettype-and-polymorphism/16681120">Eric Lippert's</a> answer, I started thinking if making <code>GetType()</code> not be virtual really ensured that an object could not lie about its <code>Type</code>.</p>
  
  <p>Specifically, Eric's answer states the following:</p>
  
  <blockquote>
    <p>The framework designers are not going to add an incredibly dangerous feature such as allowing an object to lie about its type merely to make it consistent with three other methods on the same type.</p>
  </blockquote>
  
  <p>Now the question is: can I make an object that <em>does</em> lie about its type without it being immediately obvious? I may be profoundly wrong here and I'd love clarification if that is the case, but consider the following code:</p>
  
  <pre><code>public interface IFoo
  {
      Type GetType();
  }
  </code></pre>
  
  <p>And the following two implementations of said interface:</p>
  
  <pre><code>public class BadFoo : IFoo
  {
      Type IFoo.GetType()
      {
          return typeof(int);
      }
  }
  
  public class NiceFoo : IFoo
  {
  }
  </code></pre>
  
  <p>Then if you run the following simple program:</p>
  
  <pre><code>static void Main(string[] args)
  {
      IFoo badFoo = new BadFoo();
      IFoo niceFoo = new NiceFoo();
      Console.WriteLine("BadFoo says he's a '{0}'", badFoo.GetType().ToString());
      Console.WriteLine("NiceFoo says he's a '{0}'", niceFoo.GetType().ToString());
      Console.ReadLine();
  }
  </code></pre>
  
  <p>Sure enough <code>badFoo</code> outputs an erroneous <code>Type</code>.</p>
  
  <p>Now I don't know if this has any serious implications based on Eric describing this behavior as an "<em>incredibly dangerous feature</em>", but could this pattern pose a credible threat?</p>