locked
new protected member declared in sealed class RRS feed

  • Question

  • Hi!

    I have this code

    public partial class Invoice
        {
    
            partial void Invoice_Created()
            {
                InvoiceDate = System.DateTime.Today;
                InvoiceDueDate = System.DateTime.Today.AddDays(30);
            }
    
            partial void Tax_Compute(ref decimal result)
            {
                result = GetSubTotal() * (decimal)0.21;
            }
            protected decimal GetSubTotal()
            {
                return this.InvoiceDetails.Sum(i => i.SubTotal);
            }
    
            partial void Total_Compute(ref decimal result)
            {
                result = GetSubTotal() + Tax;  // Set result to the desired field value
    
            }
    
        }

    And i get this warning:

    Warning    1    'LightSwitchApplication.Invoice.GetSubTotal()': new protected member declared in sealed class

    I am a beginner so i dont understand what is wrong because everything works fine...

    Thank you for your help!

    Friday, October 25, 2013 9:56 AM

Answers

  • Hi,

    This article should help explain why you can't declare a protected member in a sealed class. Invoice in this instance is a sealed class and since it can't be derived from, you shouldn't mark it protected. Try declaring it as private instead.

    -Pierson

    • Marked as answer by DarioOs81 Saturday, October 26, 2013 9:51 AM
    Friday, October 25, 2013 6:27 PM
    Moderator

All replies

  • Hi,

    This article should help explain why you can't declare a protected member in a sealed class. Invoice in this instance is a sealed class and since it can't be derived from, you shouldn't mark it protected. Try declaring it as private instead.

    -Pierson

    • Marked as answer by DarioOs81 Saturday, October 26, 2013 9:51 AM
    Friday, October 25, 2013 6:27 PM
    Moderator
  • Thanks! You are right. after changing

    protected decimal GetSubTotal()

    to

    private decimal GetSubTotal()

    warning was gone.


    Saturday, October 26, 2013 9:51 AM