C#具有基类和子类的多个构造函数

本文关键字:构造函数 子类 基类 | 更新日期: 2023-09-27 18:20:02

我有以下超类和子类。

我得到编译时错误:

1) Error    3   Inconsistent accessibility: parameter type 'DomainObjectModel.ObjectModel.PocoProjectData' is less accessible than method 'DomainObjectModel.ObjectModel.Project.Project(DomainObjectModel.ObjectModel.PocoProjectData)'    C:'Workspace'POC'Final'oCPDSService'oCPDSService'DomainObjectModel'ObjectModel'Project.cs   19  12  DomainObjectModel
2)Error 4   Inconsistent accessibility: parameter type 'DomainObjectModel.ObjectModel.PocoProjectData' is less accessible than method 'DomainObjectModel.ObjectModel.Project.ProjectCapacity.ProjectCapacity(DomainObjectModel.ObjectModel.PocoProjectData)'    C:'Workspace'POC'Final'oCPDSService'oCPDSService'DomainObjectModel'ObjectModel'Project.cs   102 14  DomainObjectModel
3) Error    5   Inconsistent accessibility: parameter type 'DomainObjectModel.ObjectModel.PocoProjectData' is less accessible than method 'DomainObjectModel.ObjectModel.Project.ProjectCIP.ProjectCIP(DomainObjectModel.ObjectModel.PocoProjectData)'  C:'Workspace'POC'Final'oCPDSService'oCPDSService'DomainObjectModel'ObjectModel'Project.cs   154 14  DomainObjectModel

    namespace DomainObjectModel.ObjectModel
    {  
    public class Project
    {
     public Project()
     {
      SchedulePhases = new HashSet<SchedulePhase>();
     }
     public Project(PocoProjectData pocoProjectData)
     {
      SchedulePhases = new HashSet<SchedulePhase>();
      this.AssetId = pocoProjectData.AssetID;
      this.CapitalCategoryId = pocoProjectData.CapitalCategoryID;
      this.ProgramCategoryId = pocoProjectData.ProgramCategoryID;
      this.StatusId = 1;
      this.DSFId = pocoProjectData.DsfNumber;
      this.IsRollover = "N";
      this.IsDeferred = "N";
      this.IsApproved = "N";
      this.FundingSourceId = 12;
      this.IsLongTermLease = "Y";     
     }
    [Key]
    public decimal ProjectId { get; set; }
    public decimal AssetId { get; set; }
    public decimal CapitalCategoryId { get; set; }
    public virtual ICollection<SchedulePhase> SchedulePhases { get; set; }
    protected bool success = false;
    public virtual bool CalculateSchedule(int projectType)
    {
      return success;
    }
    public class ProjectCapacity : Project
    {
      public ProjectCapacity(PocoProjectData pocoProjectData)
        : base(pocoProjectData)
      {
      }
      public override bool CalculateSchedule()
      {          
        return success;
      }
    }
    public class ProjectCIP : Project
    {
      public ProjectCIP(PocoProjectData pocoProjectData)
        : base(pocoProjectData)
      {
      }
      public override bool CalculateSchedule(int projectType)
      {        
        return success;
      }
    }
}

此外,如何从基类Project中调用子类CalculateSchedule()以获取Project.SchedulePhases集合?

谢谢,

C#具有基类和子类的多个构造函数

错误指出PocoProjectData的可访问性低于Project。Project被标记为public,所以PocoProjectData至少也需要是public。检查一下。