Re: static virtual/override



Tony Maresca wrote:

> Don't know if there are any Delphi/Object Pascal converts
> here,

I see quite a few, actually.

> I sorely miss the feature that permits
> class (e.g., static) methods to be virtual and be overridden
> in derived classes.

Why? Just curious.

> public class Foo
> {
> static void SomeMethod()
> {
> }
> }
>
> public class Bar : Foo
> {
> }
>
> Bar ABar = new Bar();
> ABar.SomeMethod();

This won't compile ... you want Bar.SomeMethod() ....

> In the above, I want the method implementation
> in Foo() to determine the class it was called through
> (in this case, Bar).

I'm drawing a blank. System.Reflection.MethodBase.GetCurrentMethod()
returns the current method, but when you call Foo.SomeMethod as
Bar.SomeMethod(), the MethodBase shows Foo for both the DeclaringType
and the ReflectedType.

Does it HAVE to be a static method?

--

www.midnightbeach.com
.



Relevant Pages