473,399 Members | 2,278 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,399 software developers and data experts.

How to get name of 'Caller' class from 'Called' class (ASP.NET)

Hi
Hope ur smart enough to get what i wanna ask ... (from the sub line

Brief Explaination
I've 2 classas Class1 and Class
Now i've an instance of Class2 ( Class2 objC2 = new Class2();
Next i access a method of Class2 (say objC2.func1();
Now in function 'func1()' of Class2 I wanna get the Caller class name ('Class1'

Plz don say me to pass the name of class as an arg in 'func()'; i need som other way ... this is coz Class2 is a central class which is used by many other classes !!

All the Best ...
Nov 18 '05 #1
4 1819
CT
This might be worth a look:
http://msdn.microsoft.com/library/de...snametopic.asp

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Hmnt" <Sa*********@hotmail.com> wrote in message
news:91**********************************@microsof t.com...
Hi,
Hope ur smart enough to get what i wanna ask ... (from the sub line)

Brief Explaination:
I've 2 classas Class1 and Class2
Now i've an instance of Class2 ( Class2 objC2 = new Class2();)
Next i access a method of Class2 (say objC2.func1();)
Now in function 'func1()' of Class2 I wanna get the Caller class name
('Class1')

Plz don say me to pass the name of class as an arg in 'func()'; i need som
other way ... this is coz Class2 is a central class which is used by many
other classes !!!

All the Best ...

Nov 18 '05 #2
This sounds like an extremely bad idea. What is Class2.func1 planning to do
with the name of its caller class, and why can't you just pass it the name
of the class as a string?

I can't recall the last time I've seen a method which needed to know who
called it. Maybe back in the early 80's...
--
John Saunders
John.Saunders at SurfControl.com
"Hmnt" <Sa*********@hotmail.com> wrote in message
news:91**********************************@microsof t.com...
Hi,
Hope ur smart enough to get what i wanna ask ... (from the sub line)

Brief Explaination:
I've 2 classas Class1 and Class2
Now i've an instance of Class2 ( Class2 objC2 = new Class2();)
Next i access a method of Class2 (say objC2.func1();)
Now in function 'func1()' of Class2 I wanna get the Caller class name ('Class1')
Plz don say me to pass the name of class as an arg in 'func()'; i need som other way ... this is coz Class2 is a central class which is used by many
other classes !!!
All the Best ...

Nov 18 '05 #3
Well
U leave me no choice but to explain the details-
Here I've to maintain a 'Log' of the classes which used the functionality of this
central-class(actually its my DB-layer file - so i need to track which class executed which
DB -object-[Stored Proc, INS/UPD/DEL...etc.

Its really pathetic to send the caller name as a string argument (and even i can't change ALL the functions already implemented !!!

Hope u understand my prob n fin me a relevent solution ...
Nov 18 '05 #4
If anyone ever looks at your log, except for debugging, I'll be surprised.
I'll be even more surprised if they get any value out of it.

The exact calling sequence down to your DB layer (please stop saying "file")
is likely to change over the course of time. Many of the changes will not be
changing the semantic reason why your DB layer was called. I hope that's
what you mean to capture by capturing the name of the calling class. BTW, I
hope you intended to capture the name of the calling method as well.

Example: today, my Employee class has a method UpdateHoursWorked which calls
the DB layer to write the updated hours to the database. Tomorrow I may
perform the exact same function by having a Timeclock class update the hours
to the database. There is no semantic difference between these two, yet
you'll be capturing different information. Good luck in making any use of
that.

You'd be better off changing all of the classes which call your DB layer to
somehow provide the DB layer with the semantics of what they are doing. The
DB layer could then log that. This could be done via a separate parameter,
or via CallContext, but the callers shouldn't care about that. Just add a
static SetSemantics method to your DB layer and let it decide how to store
the information.

--
John Saunders
John.Saunders at SurfControl.com
"Hmnt" <Sa*********@hotmail.com> wrote in message
news:D6**********************************@microsof t.com...
Well,
U leave me no choice but to explain the details--
Here I've to maintain a 'Log' of the classes which used the functionality of this central-class(actually its my DB-layer file - so i need to track which class executed which DB -object-[Stored Proc, INS/UPD/DEL...etc.]

Its really pathetic to send the caller name as a string argument (and even i can't change ALL the functions already implemented !!!)
Hope u understand my prob n fin me a relevent solution ...

Nov 18 '05 #5

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

Similar topics

15
by: Thomas Christmann | last post by:
Hi! I have a rather special question here. I'd like to write a wrapper for a .NET assembly, and register that on my server so that the people on my server call my assembly instead of the...
17
by: warteschlange | last post by:
is there a way to find out the object/function name from inside object/function. function coffee(){ alert(this.someHowGetMyNameFuncOrVar); => should give me 'coffee' } var milk = new...
1
by: mirko | last post by:
How can I collect infos about the caller class of a custom class library (dll), directly by the class library itself? I tried using the StackTrace class inside the class library, but the last...
1
by: John A Grandy | last post by:
somewhere in the .net framework libs , is the following intrinsically supplied 1. class-name & method that called the currently executing code 2. for overriden methods within a...
1
by: qingxun | last post by:
Hi! Is there a way in VB.NET to determine the caller's class name? System.Reflection.MethodBase.GetCurrentMethod.GetType basically telling me what is my current executing class, but I wanted...
6
by: antonyliu2002 | last post by:
Hi, guys, I am using Visual Web Developer Express 2005 for my web application. I wrote a simple class called MyTestClass.cs and put it in the App_Code folder. I compiled it to library from...
45
by: Zytan | last post by:
Shot in the dark, since I know C# doesn't have macros, and thus can't have a stringizer operator, but I know that you can get the name of enums as strings, so maybe you can do the same with an...
9
by: billiejoex | last post by:
Hi there, unfortunately, I'm compelled to apply a sort of monkey patching at the code of an existing libreary that I can't modify directly. Here's my question Having such code: class test: ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.