How to find types referenced inside a method body dynamically in .Net.
I mean If I have a class "A" and it has a method "Method1". "Method1"
references object of class "B" (i.e there is an object created for Class "B"
in "Method1".). Hod do I find out the object of Class "B" in "Method1"
dynamically in .net
Jon Skeet [C# MVP] - 16 Apr 2005 19:27 GMT
> How to find types referenced inside a method body dynamically in .Net.
>
> I mean If I have a class "A" and it has a method "Method1". "Method1"
> references object of class "B" (i.e there is an object created for Class "B"
> in "Method1".). Hod do I find out the object of Class "B" in "Method1"
> dynamically in .net
I'm not entirely sure what you mean. Could you give an example, with an
appropriate "what do I do here" line at the bit you don't know?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nick Stansbury - 18 Apr 2005 10:01 GMT
Hi,
I think, if I understand correctly, you are looking for the keyword
TypeOf - but I may be mistaken - here is what I think you are asking and
how to solve it
Class A
Public Sub ClassASub1()
end sub
Public ClassAInteger1 as Integer
end class
Class b
Public Sub ClassBSub1(A as string)
end sub
Public ClassBBoolean1 as Boolean
End Class
Class Test
Public Sub TestIt()
dim Obj as Object
'First set it to be an instance of class A;
Obj = new A()
if TypeOf Obj is A then
CType(Obj, A).ClassASub1()
end if
'now set it to an instance of B
Obj = new B()
if typeOf(Obj) is B then
CType(Obj, B).ClassBSub1()
end if
end sub
end class
Is that what you wanted to know - does this explain / answer the question or
have I got the wrong end of the stick?
Nick
> How to find types referenced inside a method body dynamically in .Net.
>
> I mean If I have a class "A" and it has a method "Method1". "Method1"
> references object of class "B" (i.e there is an object created for Class "B"
> in "Method1".). Hod do I find out the object of Class "B" in "Method1"
> dynamically in .net