error CS0027: Keyword 'this' is not available in the current context

13,258

The 'this' keyword refers to the current instance of the class. In the constructor, you don't have access to the instance because you are about to create one... So try below:

public partial class WizardPage1 : WizardPage
{
    public WizardPage1()
        : base(0, getLocalizedString(typeof(WizardPage1), "PageTitle"))
    {
    }
}
Share:
13,258
c00000fd
Author by

c00000fd

You can contact me at webdc2000 [ a t ] hotmail.com

Updated on June 16, 2022

Comments

  • c00000fd
    c00000fd almost 2 years

    I have the following initialization of a constructor:

    public partial class WizardPage1 : WizardPage
    {
        public WizardPage1()
            : base(0, getLocalizedString(this.GetType(), "PageTitle"))
        {
        }
    }
    

    where

    public static string getLocalizedString(Type type, string strResID)
    {
    }
    

    but this.GetType() part causes the following error:

    error CS0027: Keyword 'this' is not available in the current context

    Any idea how to resolve it?

  • c00000fd
    c00000fd over 10 years
    Is there any way to do it as typeof(this)? I'm afraid I may miss changing typeof(WizardPage1) part in a "template" class that may lead to trouble...
  • M.Babcock
    M.Babcock over 10 years
    @c00000fd - A possible alternative could be to use generics or reflection in the base class so it can glean what you mean automagically - but there's no bulletproof solution. If you can't trust your developers (including yourself) then plan for mistakes and hours of painful debugging.
  • Damith
    Damith over 10 years
    @c00000fd can you update the question with base constructor code?