我有各种生成 excel 图表的类。
每个类生成一个不同的图。
它们都共享相同的私有变量,但具有不同的值。
我希望编写一个通用代码,以防止“if”语句确定它是哪个图。
这是其中一个类的示例:
using System;
namespace GraphsGenerator
{
   public class GraphOne
   {
       #region Private Members
       private string m_baseDir = "";
       private static string m_graphName = "GraphOne";
       private string m_imageFile = m_graphName + Utils.ImageExtension;
       #endregion Private Members
       #region Properties
       public string BaseDir
       {
           set { m_baseDir = value; }
       }
       public string GraphName
       {
           get { return m_graphName; }
       }
       public string ImageFile
       {
           get { return m_imageFile; }
           set { m_imageFile = value; }
       }
       #endregion Properties
       #region Constructor
       public HandTrackingGraphs(string baseDir)
       {
           m_baseDir = baseDir;
       }
       #endregion Constructor
   }
 }
我试图在我的主要做到这一点:
List<object> listOfGraphs = new List<object>();
listOfGraphs.Add(new GraphOne());
listOfGraphs.Add(new GraphTwo());
listOfGraphs.Add(new GraphThree());
foreach (object currentGraph in listOfGraphs)
{
   string imageFile = currentGraph.ImageFile;
}
但是,这当然是做不到的。
有任何想法吗?