title: Create a generic method to use EqualityComparer that I have defined for specific types
body: <p>I have many objects in which I want to check that lists of those objects are equal.</p>
  <p>For each object I have defined an EqualityComparer:</p>
  <pre><code>public class BaseAssociatedEntity : BasePage
  {
      protected IWebElement EntityElement;
      protected virtual IWebElement EntityLink =&gt; EntityElement.FindElement(By.TagName(&quot;a&quot;));
      public string EntityName =&gt; EntityLink.Text;
  
      public BaseAssociatedEntity(IWebElement entityElement, IWebDriver driver, string username, string password) 
          : base(driver, driver.Url, username, password, TimeoutInSecondsConstants.Three)
      {
          EntityElement = entityElement;
      }
  
      public bool Equals(BaseAssociatedEntity that)
      {
          return EntityName == that.EntityName;
      }
  }
  
  public class BaseAssociatedEntityEqual : EqualityComparer&lt;BaseAssociatedEntity&gt;
  {
      public override bool Equals(BaseAssociatedEntity x, BaseAssociatedEntity y)
      {
          if (ReferenceEquals(x, y)) return true;
          if (x is null || y is null) return false;
  
          return x.Equals(y);
      }
  
      public override int GetHashCode(BaseAssociatedEntity obj) =&gt; obj.GetHashCode();
  }
  </code></pre>
  <p>I then want to call the following method to check that 2 lists of type BaseAssociatedEntity are SequenceEqual():</p>
  <pre><code>protected bool BothNullOrEqual(List&lt;BaseAssociatedEntity&gt; left, List&lt;BaseAssociatedEntity&gt; right)
  {
      if (left == null &amp;&amp; right == null) return true;
      if (left != null &amp;&amp; right != null) return left.SequenceEqual(right, new BaseAssociatedEntityEqual());
      return false;
  }
  </code></pre>
  <p>But I end up writing this BothNullOrEqual method for every single object that I have:</p>
  <pre><code>protected bool BothNullOrEqual(List&lt;NotificationGroupAssociatedEntity&gt; left,
      List&lt;NotificationGroupAssociatedEntity&gt; right)
  {
      if (left == null &amp;&amp; right == null) return true;
      if (left != null &amp;&amp; right != null) return left.SequenceEqual(right, new NotificationGroupAssociatedEntityEqual());
      return false;
  }
  </code></pre>
  <p>And so on.. How can I make this method generic so that it works for all types, using the EqualityComparer that I have specifically defined?</p>