-
static method question
Is there some way inside a static method to determine whether it is being
called on a base class or an inherited class. For instance:
public class BaseClass
{
public BaseClass() {}
public static MyMethod()
{
}
// other non-static methods
}
public class InheritedClass : BaseClass
{
public InheritedClass() {}
//notice this one doesn't implement or override MyMethod
}
So is this there a way to determine inside of MyMethod whether it was called
via BaseClass.MyMethod or InheritedClass.MyMethod?
If it wasn't static I could use "this" to get its type. So how do I do it
since it is static?
Thanks
Sean
-
Re: static method question
"Sean Woods" <swoods@eclickmd.com> wrote:
>Is there some way inside a static method to determine whether it is being
>called on a base class or an inherited class.
>
>So is this there a way to determine inside of MyMethod whether it was called
>via BaseClass.MyMethod or InheritedClass.MyMethod?
>
>If it wasn't static I could use "this" to get its type. So how do I do
it
>since it is static?
>
>Thanks
>Sean
If you use nonstatic methods, you can use this.GetType() to find out what
sort of class you're in.
... Or you can override a virtual method and have different behavior based
on the object type.
But you can't know what type of "class" you're in from a static non-virtual
method.
(Unless I'm wrong!)
-- Jeff
-
Re: static method question
As far as my knowledge goes, you cannot call a static method using the
object reference. You have to use the class name to do so. In these
scenario, does it really matter whether I am calling the function of the
base or the derived class? I know the type before making the call.
"Jeff Johnson" <jeff@nospam.com> wrote in message
news:3e4d1d22$1@tnews.web.devx.com...
>
> "Sean Woods" <swoods@eclickmd.com> wrote:
> >Is there some way inside a static method to determine whether it is being
> >called on a base class or an inherited class.
> >
> >So is this there a way to determine inside of MyMethod whether it was
called
> >via BaseClass.MyMethod or InheritedClass.MyMethod?
> >
> >If it wasn't static I could use "this" to get its type. So how do I do
> it
> >since it is static?
> >
> >Thanks
> >Sean
>
>
> If you use nonstatic methods, you can use this.GetType() to find out what
> sort of class you're in.
>
> .. Or you can override a virtual method and have different behavior based
> on the object type.
>
> But you can't know what type of "class" you're in from a static
non-virtual
> method.
>
> (Unless I'm wrong!)
>
> -- Jeff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks