473,320 Members | 1,887 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,320 software developers and data experts.

How to know the Calling Object ?

vsr
I am calling one Method in Common class from different classes and i want to
know from which object the call is coming from.. is there any way?
Mar 29 '06 #1
7 3300
"vsr" <vs*@discussions.microsoft.com> schrieb:
I am calling one Method in Common class from different classes and i want
to
know from which object the call is coming from.. is there any way?


No, because this wouldn't make sense in any scenario I can think of. Why
exactly would you need this information?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 29 '06 #2
There is a way using the stacktrace and stackframe, but I agree with
Herfried that there are few if any situations in which it would be
useful / the goal could not be achieved in some other way.

What are you trying to achieve?

Alan?

Mar 29 '06 #3
vsr
May be you are right , this may not be the approach.
I created some classes (these classes are not visible) , and created one
Routing Class.
I want to call those classes through the Routing Class......
Ex:-
Class1,Class2,Class3 (all these classes will have same methods with
different implementation)
RoutingClass (this has GetObject method)

RoutingClass.GetObject should return appropriate Object based on the Object

Is it meaning full???

"AlanT" wrote:
There is a way using the stacktrace and stackframe, but I agree with
Herfried that there are few if any situations in which it would be
useful / the goal could not be achieved in some other way.

What are you trying to achieve?

Alan?

Mar 30 '06 #4

"vsr" <vs*@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
I am calling one Method in Common class from different classes and i want
to
know from which object the call is coming from.. is there any way?


A [properly encapsulated] method really shouldn't care who called it.

If your method /really/ needs to know who called it, pass [a reference to]
the caller as an argument to the method.
Or have different callers use different methods.

Regards,
Phill W.
Mar 30 '06 #5
>From the description it looks like you can just use an interface or
common base class to give each of Class1, Class2, Class3 a common
'Interface' (same methods, different implementation) but I am unsure
about what the Routing class is intended to do

What does 'return the appropriate Object(1) based on the Object(2)'
mean?

It looks like Object(1) is one of class1, class2, class3 et al. but
what is Object(2)?

Alan.

Mar 30 '06 #6
vsr
You are right , we could use Interfaces in place of this , i am trying to go
without interfaces.. anyway thank you for the info , now i think i can design
to accomodate interfaces..

Object2 is the which is trying to call Object1.sorry for the confusion.

"AlanT" wrote:
From the description it looks like you can just use an interface or

common base class to give each of Class1, Class2, Class3 a common
'Interface' (same methods, different implementation) but I am unsure
about what the Routing class is intended to do

What does 'return the appropriate Object(1) based on the Object(2)'
mean?

It looks like Object(1) is one of class1, class2, class3 et al. but
what is Object(2)?

Alan.

Mar 30 '06 #7
> "vsr" <vs*@discussions.microsoft.com> schrieb:
I am calling one Method in Common class from different classes and i
want
to
know from which object the call is coming from.. is there any way?

No, because this wouldn't make sense in any scenario I can think of.
Why exactly would you need this information?


I agree that in most cases, you would break encapsulation by doing this.
Since you did not mention what your goal was, it is hard to know if there
wouldn't be a way of achieving the result. It is possible in 2005 using the
Diagnostics.StackTrace.GetFrame method as follows:

Dim propertyName As String = _
New System.Diagnostics.StackTrace(). _
GetFrame(1).GetMethod.Name

That being said, it is possible that the functionality you wish to achieve
could be better accomplished using Aspects. You may want to read up on Aspect
Oriented Programming a bit to see if it could accomplish what you wish to do.
Mar 30 '06 #8

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

Similar topics

14
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
30
by: Tim Marshall | last post by:
Here's the scenario, A2003, Jet back end, illustrated with some cut down code at the end of the post: A proc dims a snapshot recordset (dim rst as Dao.recordset) and opens it. There are several...
14
by: mluvw47 | last post by:
Know the answers to the following? Line Contains 50 char *b, q, *r; 200 b = getbuf (); 201 q = *b; 212 R = anotherfunction (b); 213-2003 /* we want to use 'q' and 'r'...
1
by: Philipp Ott | last post by:
Hello! I would like to send a method based on a string to an object. In Smalltalk, Ruby and Objective-C exists a respondsto: method which allows you to ask an object dynamically if it responds...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
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...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.