title: How to convert T object to IEnumerable<T>
body: <p>I have following method</p>
  <pre><code>public static IRuleBuilderOptions&lt;T, Guid&gt; MustExistInDatabase&lt;T, TEntity&gt;
      (
          this IRuleBuilder&lt;T, Guid&gt; ruleBuilder,
          TEntity obj
      ) where TEntity : class
  {
      if (obj == null)
          return ruleBuilder.Must(id =&gt; false)
              .WithMessage(&quot;'{PropertyName}' {PropertyValue} not found.&quot;);
  
      var isCollection = obj.GetType().GetInterface(nameof(IEnumerable)) != null;
  
      if (isCollection)
      {
          var list = (obj as IEnumerable&lt;TEntity&gt;); //I get a null here
          
          if (list.Count() == 0)
          {
              //rest of code
          }
      }
      else
      {
          //rest of code
      }
  }
  </code></pre>
  <p>I want to check whether <code>obj</code> is an <code>IEnumerable</code> or not, if it's an <code>IEnumerable</code>, then I want to convert <code>obj</code> into <code>IEnumerable&lt;T&gt;</code>, but I'm getting <code>null</code> when doing <code>(obj as IEnumerable&lt;TEntity&gt;)</code>. What is the correct syntax to do this?</p>