473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calling Class and Static

In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!

I have tried MethodInfo.GetCurrentMethod().ReflectedType ... but that
returns back MyClass.
public class MyClass
{
public static string Test()
{

}

}

public class MyDerived : MyClass
{
}


MyDerived.Test();

Nov 16 '05 #1
4 969
msnews.microsoft.com <bk****@fakedomain.com> wrote:
In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!


No. It actually gets compiled to a call to MyClass.Test anyway.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Ahh ... good point. i hadn't thought of checking out the generated code ...

Thanks!

Brett

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
msnews.microsoft.com <bk****@fakedomain.com> wrote:
In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!


No. It actually gets compiled to a call to MyClass.Test anyway.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

You might be able to determine that from
new StackTrace().

Jose Solorzano

msnews.microsoft.com wrote:
In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!

I have tried MethodInfo.GetCurrentMethod().ReflectedType ... but that returns back MyClass.
public class MyClass
{
public static string Test()
{

}

}

public class MyDerived : MyClass
{
}


MyDerived.Test();


Nov 16 '05 #4
Yea ... I had thought of that, but here are the results

at MyClass.Test()
at MyClass.Main()

Brett


"Jose Solorzano" <jh******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

You might be able to determine that from
new StackTrace().

Jose Solorzano

msnews.microsoft.com wrote:
In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!

I have tried MethodInfo.GetCurrentMethod().ReflectedType ... but that

returns back MyClass.
public class MyClass
{
public static string Test()
{

}

}

public class MyDerived : MyClass
{
}


MyDerived.Test();

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
13
by: RainBow | last post by:
Hi everyone, (Very Sorry, if this is the wrong group in which I am posting this query). Code snippet: //C library typedef int (*PFunc)(int* aArg); void call_c_foo(PFunc aPtrtoFunc) {
2
by: Jan | last post by:
Here's the code with the problem: class Startup { public static string Sym; public static string PrevDate; public static int Highest = new int; // ______________
6
by: Mirek Endys | last post by:
Hello all, another problem im solving right now. I badly need to get typeof object that called static method in base classe. I did it by parameter in method Load, but i thing there should be...
6
by: Anthony Smith | last post by:
I can call a class using "->", but it complains about the :: I see on the net where :: is used. Is there a good explanation on when to use one over the other or the differences? $help = new...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below is pretty simple. Calling Talker() in the parent returns "Parent", and calling Talker() in the child returns "Child". I'm wondering how I can modify the code so that a call to the...
2
by: Dragan | last post by:
Hi, We're working in VS 2005, Team edition, if it makes any difference at all (should be up-to-date and all that, but could not guarantee it is 100%). We've implemented a simple generic wrapper...
1
by: newbie | last post by:
This is a snippet from C++ FAQs, which I have never done--- when I do such a thing, I would declare function used by constructor ( in this example, init() ) as static. But I do understand that it...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.