Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2005

Tip: Looking for answers? Try searching our database.

Finding types inside a method body dynamically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bidyadhar Patra - 16 Apr 2005 08:43 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
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.