By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

In a base class, can I make one property accesser abstract, but put code in the other one?

P: n/a
I have a base class that defines a property. I'd like the the Get to be
implemented by the base class and not overrideable. I would like the Set to
be marked abstract, and thus needs to be filled in by overriding classes.
Is this possible? What's the syntax?
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
That not possible I'm afraid. You could provide a abstract and seperate Set
method.

You could have a protected Set method, and a sealed property, but have your
property call the set method. Like this...

public int MyProp
{
get
{
return myInt;
}
set
{
SetMyInt( value );
}
}

protected abstract SetMyInt( int theInt )
{
//Set the int
}

This way, from the public interface perspective, the derived class will
behave as if it had a polymorphic Set on the property.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
"0to60" <ho****************@yahoo.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
I have a base class that defines a property. I'd like the the Get to be
implemented by the base class and not overrideable. I would like the Set to be marked abstract, and thus needs to be filled in by overriding classes.
Is this possible? What's the syntax?

Nov 17 '05 #2

P: n/a
The short answer is "no", however ....

did you know .... your

string MyProperty { get { /* */} set{ /* */} }

is converted into

string get_MyProperty() { }
void set_MyProperty(string value) { }

pretty much the same way COM properties are translated, so .... why not
provide methods in the first instance, that way you can do the following ...

public sealed string MyProperty { get { } }
public abstract void SetMyProperty(string value) { }

for example

--
--

Of all words of tongue and pen, the saddest are: "It might have been"
"0to60" wrote:
I have a base class that defines a property. I'd like the the Get to be
implemented by the base class and not overrideable. I would like the Set to
be marked abstract, and thus needs to be filled in by overriding classes.
Is this possible? What's the syntax?

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.