how do i put an abstract property in base form

P

parez

how do i put an abstract property ( or something that lets me know
that derived class has not implemented that particular property ) in
base form in my win forms project?

if i make the base form abstract then i cannot use the designer?

I could use "throw new NotImplementedException();" in the base form
property. then i will find out at runtime rather than compile time.

TIA
 
P

parez

Well, you can't use the designer with the base class, that's right. It
might prevent using the designer from a derived class too, but you should
check that before worrying about it. I recall some specific rules about
how sub-classed sub-classes of the Form class work with the Designer, but
don't remember the specifics. :)

Yes. When i said "i cannot use the desinger", I meant all the
derived forms forms. I lost a few sentences between the thinking and
the typing. ;)

Actually the base form works just fine.

Have you run into some specific problem using the Designer with a
sub-class of an abstract class?


I get an error message of the type "the designer must have an instance
of the type..blah blah .. but it cannot because its an abstract type"
Yes, you could, for a virtual (not abstract) property. Of course, that
would rely on some code actually _using_ the property for you to find out
it hadn't been implemented.

This property would be used in the FormActivated event in the base
form so i would know right away when the form shows if it is not
implemented and fix it right away.

A less-risky alternative, though perhaps a
bit more "hacky", would be to include some code in the constructor of the
base class that uses reflection to look for a sub-class implementation of
the property in question.


I was looking for a compile time check.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top