title: Comma Separated Values on a Net 6 Minimal Api parameter
body: <p>Usings Net 6 Minimal API I have the following route:</p>
  <pre><code>builder.MapGet(&quot;posts&quot;, async ([FromQuery] IEnumerable&lt;Int32&gt; postsIds) =&gt; {
  });
  </code></pre>
  <p>The parameters <code>postsIds</code> contains the <code>ids</code> of posts to be loaded, e.g., &quot;1, 3, 5&quot;.</p>
  <p>I get the following error when running the application:</p>
  <blockquote>
  <p>Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Http.Extensions.dll: 'No public static bool IEnumerable.TryParse(string, out IEnumerable) method found for postsIds.</p>
  </blockquote>
  <p>So I created the following:</p>
  <pre><code>public class CommaSeparatedValues&lt;T&gt; {
  
    public IEnumerable&lt;T&gt; Values { get; set; } = new List&lt;T&gt;();
  
    public static Boolean TryParse(String? value, IFormatProvider? provider, out CommaSeparatedValues&lt;T&gt;? commaSeparatedValues) {
  
      IEnumerable&lt;T&gt;? values = value?.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Cast&lt;T&gt;();
  
      if (values is null) {
        commaSeparatedValues = null;
        return false;
      }
  
      commaSeparatedValues = new CommaSeparatedValues&lt;T&gt; { Values = values };
      return true;
  
    } 
  </code></pre>
  <p>And changed the endpoint to:</p>
  <pre><code>builder.MapGet(&quot;posts&quot;, async ([FromQuery] CommaSeparatedValues&lt;Int32&gt; postsIds) =&gt; {
  });
  </code></pre>
  <p>Does this make sense? Can I improve / simplify this approach? Or this is the way?</p>