Note that there are some explanatory texts on larger screens.

plurals
  1. POreturning a list<interface> in C#
    primarykey
    data
    text
    <p>Edited after initial suggestions about using IEnumerable instead of List.</p> <p>I am trying to do this:</p> <pre><code>public interface IKPIDetails // Previously: interface IKPIDetails { string name {get; set;} //... } public abstract class BaseReport { public List&lt;IKPIDetails&gt; m_KPIDetails; // Previously: list&lt;IKPIDetails&gt; m_KPIDetails; public BaseReport() { m_KPIDetails = MakeReportDataStructure(); //... } public abstract List&lt;IKPIDetails&gt; MakeReportDataStructure(); // Previously: public abstract IKPIDetails MakeReportDataStructure(); //... } public class AirTemp_KPIDetails : NetVisSolution.Reports.IKPIDetails // Previously: protected class AirTemp_KPIDetails : IKPIDetails { #region IKPIDetails implementation private string _Name; public string Name { get { return _Name; } set { _Name = value; } } #endregion ... } public class SSAirTempSummaryReport : BaseReport { public SSAirTempSummaryReport() : base () { // Do any extra initialisation here m_reportName = "Air Temperature Summary Report"; } //It now complains on the declaration below at the word // MakeReportDataStructure() public override IEnumerable&lt;IKPIDetails&gt; MakeReportDataStructure() // Previously: public override List&lt;IKPIDetails&gt; MakeReportDataStructure() { List&lt;AirTemp_KPIDetails&gt; d = new List&lt;AirTemp_KPIDetails&gt;(); return d; // &lt;-- this is where it used to break } //... } </code></pre> <p>So I have a report data object interface and potentially multiple report data classes implementing this interface and adding their specific extra bits. And I have an abstract report class implementing generic report functionality and multiple derived classes that each use their own report data class.</p> <p>Unfortunately, when I try to create a list of my report detail structures in the derived class and pass it back to the base class as a list of the interface, it complains: </p> <pre><code>Cannot implicitly convert type 'System.Collections.Generic.List&lt;NetVisSolution.Reports.AirTemp_KPIDetails&gt;' to 'System.Collections.Generic.List&lt;NetVisSolution.Reports.IKPIDetails&gt;' </code></pre> <p>It won't let me do it implicitely or explicitly. Is there any way that I can do this?</p> <p>Thanks in advance,</p> <p>--- Alistair.</p>
    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.
    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