|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to know the Calling Object ?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? "vsr" <v**@discussions.microsoft.com> schrieb: No, because this wouldn't make sense in any scenario I can think of. Why >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? 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/> > "vsr" <v**@discussions.microsoft.com> schrieb: I agree that in most cases, you would break encapsulation by doing this. > >> 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? > 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. 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? 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??? Show quoteHide quote "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? > > >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. 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. Show quoteHide quote "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. > > "vsr" <v**@discussions.microsoft.com> wrote in message A [properly encapsulated] method really shouldn't care who called it.news:7F32A145-905C-423B-BFD7-A8A1FD11C6C0@microsoft.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? 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.
Update Access data
My computer seems to be to slow to run VS2005 REPOST: preventing more than one user from working on the same record Calendar with custom tooltip over days with events XML into datagrid System Volume Information VB.NET error Using Find method on a List(of type) Breaks the Reference Locked Control Using Class's and multiThreading |
|||||||||||||||||||||||