# GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten_" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten*">Flatten Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten_" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten*"></a>
<h4 id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten__1_System_Collections_Generic_IEnumerable___0__System_Func___0_System_Collections_Generic_IEnumerable___0___" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten``1(System.Collections.Generic.IEnumerable{``0},System.Func{``0,System.Collections.Generic.IEnumerable{``0}})">Flatten&lt;T&gt;(IEnumerable&lt;T&gt;, Func&lt;T, IEnumerable&lt;T&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>This method extends the LINQ methods to flatten a collection of items that have a property of children of the same type.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IEnumerable&lt;T&gt; Flatten&lt;T&gt;(this IEnumerable&lt;T&gt; source, Func&lt;T, IEnumerable&lt;T&gt;&gt; childSelector)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;</td>
      <td><span class="parametername">source</span></td>
      <td><p>Source collection.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;T, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;&gt;</td>
      <td><span class="parametername">childSelector</span></td>
      <td><p>function that returns a collection of children for each item</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;</td>
      <td><p>Returns a one level list of elements of type T.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">T</span></td>
      <td><p>Item type</p>
</td>
    </tr>
  </tbody>
</table>


<a id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten_" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten*"></a>
<h4 id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten__1___0_System_Func___0_System_Collections_Generic_IEnumerable___0___" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten``1(``0,System.Func{``0,System.Collections.Generic.IEnumerable{``0}})">Flatten&lt;T&gt;(T, Func&lt;T, IEnumerable&lt;T&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>This method extends the LINQ methods to obtain a single-level collection of descendants(is a collections) of an object of type T</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IEnumerable&lt;T&gt; Flatten&lt;T&gt;(this T source, Func&lt;T, IEnumerable&lt;T&gt;&gt; childSelector)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">T</span></td>
      <td><span class="parametername">source</span></td>
      <td><p>The object of type T.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;T, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;&gt;</td>
      <td><span class="parametername">childSelector</span></td>
      <td><p>function that returns a collection of children</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;</td>
      <td><p>Returns a one level list of elements of type T.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">T</span></td>
      <td><p>Item type.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten_" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten*"></a>
<h4 id="GrapeCity_Enterprise_Data_Expressions_Tools_EnumerableExtensions_Flatten__1___0_System_Func___0___0__" data-uid="GrapeCity.Enterprise.Data.Expressions.Tools.EnumerableExtensions.Flatten``1(``0,System.Func{``0,``0})">Flatten&lt;T&gt;(T, Func&lt;T, T&gt;)</h4>
<div class="markdown level1 summary"><p>This method extends the LINQ methods to obtain a single-level collection of descendants(is an object) of an object of type T</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IEnumerable&lt;T&gt; Flatten&lt;T&gt;(this T source, Func&lt;T, T&gt; childSelector)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">T</span></td>
      <td><span class="parametername">source</span></td>
      <td><p>The object of type T.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;T, T&gt;</td>
      <td><span class="parametername">childSelector</span></td>
      <td><p>function that returns of children object of type T.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;</td>
      <td><p>Returns a one level list of elements of type T.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">T</span></td>
      <td><p>Item type.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
