Finding types inside a method body dynamically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Bidyadhar Patra said:
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?
 
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
 
Back
Top