title: Should derived classes hide the Default and Create static members inherited from Comparer<T>?
body: <p>I am writing an <code>IComparer&lt;T&gt;</code> implementation by deriving from the <code>Comparer&lt;T&gt;</code> class, as <a href="https://msdn.microsoft.com/en-us/library/cfttsh47%28v=vs.110%29.aspx">recommended by MSDN</a>. For example:</p>
  
  <pre><code>public class MyComparer : Comparer&lt;MyClass&gt;
  {
      private readonly Helper _helper;
  
      public MyComparer(Helper helper)
      {
           if (helper == null)
               throw new ArgumentNullException(nameof(helper));
  
          _helper = helper;
      }
  
      public override int Compare(MyClass x, MyClass y)
      {
          // perform comparison using _helper
      }
  }
  </code></pre>
  
  <p>However, under this approach, the <code>MyComparer</code> class inherits the <code>Default</code> and <code>Create</code> static members from the <code>Comparer&lt;T&gt;</code> class. This is undesirable, since the implementation of the said members is unrelated to my derived class, and may lead to misleading behaviour:</p>
  
  <pre><code>// calls MyClass.CompareTo or throws InvalidOperationException
  MyComparer.Default.Compare(new MyClass(), new MyClass());
  </code></pre>
  
  <p>My comparer cannot have a default instance due to the required <code>Helper</code> argument, nor can it initialize itself from a <code>Comparison&lt;T&gt;</code>, so I cannot hide the inherited static members with meaningful implementations.</p>
  
  <p>What is the recommended practice for such situations? I'm considering three options:</p>
  
  <ul>
  <li><p>Implement <code>IComparer&lt;T&gt;</code> manually, rather than deriving from <code>Comparer&lt;T&gt;</code>, so as to avoid inheriting the said static members</p></li>
  <li><p>Leave the inherited static members in place, and assume consumers will know not to use them</p></li>
  <li><p>Hide the inherited static members with new implementations that throw <code>InvalidOperationException</code>:</p>
  
  <pre><code>public static new Comparer&lt;MyClass&gt; Default
  {
      get { throw new InvalidOperationException(); }
  }
  
  public static new Comparer&lt;MyClass&gt; Create(Comparison&lt;MyClass&gt; comparison)
  {
      throw new InvalidOperationException();
  }
  </code></pre></li>
  </ul>