Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Generics Efficiency, a better way to do this
    primarykey
    data
    text
    <p>Ok, lets say I have classes such as the following:</p> <pre><code>public class KPIObject&lt;T&gt; //&lt;--This class where T is the following classes { public List&lt;T&gt; Data { get; set; } public string Caption { get; set; } } public class KPICycleCountAccuracyData //&lt;--There are 20 of these with different names and values { public string Facility { get; set; } public string CCAdjustedCases { get; set; } public string TotalCases { get; set; } public string CCAdjustedPercent { get; set; } } </code></pre> <p>Then I have:</p> <pre><code>public List&lt;ReportData&gt;&gt; ProcessAccountReport(GetAccountReport request) { var data = new List&lt;ReportData&gt;(); ProcessKPI(data, request.KPICycleCountAccuracy, "KPICycleCountAccuracy"); //&lt;-- 20 of these return data; } </code></pre> <p>Here is the ProcessKPI method:</p> <pre><code>private static void ProcessKPI&lt;T&gt;(List&lt;ReportData&gt; data, ICollection&lt;KPIObject&lt;T&gt;&gt; items, string name) { if (items == null || items.Count &lt;= 0) return; foreach (var item in items) { if (item.Data == null || item.Data.Count &lt;= 0) continue; var temp = new List&lt;object&gt;(); temp.AddRange((IEnumerable&lt;object&gt;)item.Data); data.Add(new ReportData { Data = temp, Name = name, Title = item.Caption }); } } </code></pre> <p>All of this works and compiles correctly, I am just wondering if this is the most efficient way of doing this.</p> <p>Thanks.</p> <p><strong>EDIT</strong></p> <p>I changed process KPI to this:</p> <pre><code>private static void ProcessKPI&lt;T&gt;(ICollection&lt;ReportData&gt; data, ICollection&lt;KPIObject&lt;T&gt;&gt; items, string name) { if (items == null || items.Count &lt;= 0) return; foreach (var item in items.Where(item =&gt; item.Data != null &amp;&amp; item.Data.Count &gt; 0)) { data.Add(new ReportData { Data = (IEnumerable&lt;object&gt;)item.Data, Name = name, Title = item.Caption }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload