In C#, can I hide/modify accessors in subclasses?

Posted by Diego on Stack Overflow See other posts from Stack Overflow or by Diego
Published on 2010-03-28T20:11:27Z Indexed on 2010/03/28 20:13 UTC
Read the original article Hit count: 327

Filed under:
|
|
|

I'm not even sure what this principle is called or how to search for it, so I sincerely apologize if it has been brought up before, but the best way to do it is with an example.

class Properties

{ public string Name { get; set; } }

class MyClass { class SubProperties: Properties { public override Name { get { return GetActualName(); } set { _value = SetActualName(value); } } }

public SubProperties ClassProperties;

private GetActualName() { ClassProperties.Name = "name"; }

private SetActualName(string s) { ClassProperties.Name = SomeOtherFunction(s); } }

The idea is to have any object that instantiates MyClass have a fully accessible property ClassProperties. To that object, it would look exactly like a Properties object, but behind the scenes, MyClass is actually computing and modifying the results of the fields. This method of declaration is obviously wrong since I can't access GetActualName() and SetActualName() from within the SubProperties definition. How would I achieve something like this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about accessors