C # Abstract class usage - getting errors Inconsistency Accessibility

I had one class that was used ConfirmNonInventoryViewModel, but then I had to come up with a different type of object, which was very similar, but with one other property (which may have more unique properties as functionality increases).

So, I wanted to turn this original class into a base class, and then create 2 derived classes to account for two unique variants of objects. But since I have code around already using the original class and I don’t want it, and therefore the developers do not use this base class directly ahead, I thought that its designation as abstractwould not allow it to be used and only derivative variants could be used like that.

But it gives me errors like Inconsistent Accessibility: base class is less accessible than derived class. Therefore, I think I misunderstood what the abstract class is used for.

How can I satisfy my requirements as described above?

public class ConfirmWorkOrderNonInventoryViewModel : ConfirmNonInventoryViewModel
{
    [Display(Name = "Part:")]
    public int WorkOrderDetailId { get; set; }     
}

public class ConfirmShipOrderNonInventoryViewModel : ConfirmNonInventoryViewModel
{
    [Display(Name = "Order:")]
    public int OrderHeaderId { get; set; }
}

abstract class ConfirmNonInventoryViewModel
{
    [Display(Name = "Part:")]
    public int OrderDetailId { get; set; }

    [Display(Name = "Material:")]
    public string ItemDescription { get; set; }

    [Display(Name = "Est Qty:")]
    public decimal EstimatedQty { get; set; }

    [Required]
    [Display(Name = "Act Qty:")]
    [UIHint("TextBoxFor_50w")]
    public decimal? ConfirmedQty { get; set; }
}
+4
source share
1 answer

Just add publicto your class so that it becomes the following:

public abstract class ConfirmNonInventoryViewModel{
   //...
}

Thus, your base class has the same availability as derived classes.

+5
source

Source: https://habr.com/ru/post/1626470/


All Articles