Forums

How do you override a protected method?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

How do you override a protected method?

Postby AlGonzalez » Wed Feb 13, 2008 10:05 am

I'm trying to implement the disposable pattern on a form by overriding the base form dispose method.

Code: Select all
    var _components as IContainer?

    def dispose(disposing as bool) #is override
        if disposing and _components
            _components.dispose
        base.dispose(disposing)


I get this warning: "TestForm.Dispose(bool)" hides inherited member "System.Windows.Forms.Form.Dispose(bool)". To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

If I uncomment the 'is override', I get this error: "TestForm.Dispose(bool)": cannot change access modifiers when overriding "protected" inherited member "System.ComponentModel.Component.Dispose(bool)"
AlGonzalez
 
Posts: 13
Location: Greenville, SC - USA

Re: How do you override a protected method?

Postby khjklujn » Wed Feb 13, 2008 1:03 pm

They aren't in Chuck's list of keywords, so this may be a soon-to-be deprecated syntax, but public, protected, and private are recognized keywords in version 0.7.2.

To override a protected method try:
def dispose(disposing as bool) is protected, override
khjklujn
 
Posts: 29

Re: How do you override a protected method?

Postby AlGonzalez » Wed Feb 13, 2008 3:11 pm

Excellent - thank you very much.

I thought I'd tried every combination, but apparently not.
AlGonzalez
 
Posts: 13
Location: Greenville, SC - USA

Re: How do you override a protected method?

Postby Charles » Thu Feb 14, 2008 1:56 am

It's not a soon-to-be-deprecated syntax so feel free to use it. They are pseudo keywords meaning they are recognized in this syntax, but you can otherwise use them for variable names. By the way, I call these particular ones "is names" in the docs.

And straight from the compiler source:
_validIsNames = ['fake', 'shared', 'virtual', 'nonvirtual', 'override', 'new', 'public', 'protected', 'private', 'internal', 'abstract']

Thanks for asking these questions. I've internalized a lot of Cobra so I forget to mention these things.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 126 guests

cron