Reputation: 185
I want to track TopMost
property changes in my custom forms which are referred as (Form)
. I cannot use override
, because TopMost
isn't abstract
or virtual
, I can't use new
keyword because it has no effect while implicit referring.
What is the best way to deal with such a task? We can substitute any property instead TopMost
as long as base class (Form
) has neither "change"-event, nor ONSomething virtual method to override, and our property isn't marked as abstract
or virtual
.
Example:
I have many classes based on Form
MyForm1:Form, class MyForm2:Form, class MyForm_n:Form
Some "factory" returns instances of Form
type
Form f = GetMyForm();
And finally i do
f.TopMost = !f.TopMost;
The deal is that I can't really use any other return type for Form GetMyForm()
. I can't use interface
or other base class except actual Form
one (in fact, there is no factory, I use .ParentForm
property of some control).
What is the best way to acheive task and keep my code as clean as possible? Thanks in advance.
Upvotes: 2
Views: 585
Reputation: 1500875
It sounds like you might want to introduce a new abstract class between your concrete classes and Form
. That could have an ObservedTopMost
property or something like that, which delegates to TopMost
but also raises an event.
It's important to note that that this will only be useful when the new property is used; it won't magically spot changes to the existing property from elsewhere. It might be good enough for your purposes though.
Upvotes: 2