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 / CLR / June 2004

Tip: Looking for answers? Try searching our database.

method content

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
s zemp - 09 Jun 2004 19:51 GMT
how can i get method content by reflection or other way
like ILdasm doing
Mattias Sj?gren - 10 Jun 2004 01:32 GMT
>how can i get method content by reflection or other way?

Reflection doesn't support that in v1.x (but will in v2.0 I believe).
So you either have to write your own managed executable reader (the
file format is well documented) or use some existing library (there
are a few available, for example from
http://www.aisto.com/roeder/dotnet/).

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Chad Z. Hower aka Kudzu - 10 Jun 2004 15:10 GMT
=?Utf-8?B?cyB6ZW1w?= <shayhandelman@hotmail.com> wrote in news:F4750901-478F-
421C-A5B2-83B35002EF54@microsoft.com:
> how can i get method content by reflection or other way?
> like ILdasm doing

Try Lutz's reflector. It decompiles methods into C#, VB, or Delphi.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
     "Programming is an art form that fights back"

Make your ASP.NET applications run faster
 http://www.atozed.com/IntraWeb/
Alicia Li - 11 Jun 2004 16:41 GMT
There is not public refection APIs do it in V1.1, but in V2.0, you will be
able to do so.

Below is simple code:

//TargetMethod is methodinfo of the method that you want to inspect
MethodBody methodBody = TargetMethod.GetMethodBody();

// get local variables in to a collection. Then you can inspect them very
easily
IList<LocalVariableInfo> Locals  = methodBody.LocalVariables;
Bool bInitLocals = methodBody.InitLocals;

//if you want to parse IL, you need to work on the byte[].
Byte[] IL = methodBody.GetILAsByteArray();

//get exception handling clases into a collection, then you can inspect
them.
IList<ExceptionHandlingClause>  ehClauses =
methodBody.ExceptionHandlingClauses;


Below are the new APIs in V2.0:


MethodBase.GetMethodBody()

namespace System.Reflection

{

     public sealed class MethodBody

     {

           // This class can only be created from inside the EE.

           private MethodBody() { }



           public int LocalSignatureMetadataToken { get; }

           public IList<LocalVariableInfo> LocalVariables { get; }

           public int MaxStackSize { get; }

           public bool InitLocals { get; }

           public byte[] GetILAsByteArray();

           public IList<ExceptionHandlingClause> ExceptionHandlingClauses
{ get; }

     }

}

1.1. (System.Reflection.LocalVariableInfo)


namespace System.Reflection

{

     public class LocalVariableInfo

     {

           internal LocalVariableInfo() { }



           public override string ToString();



           public virtual Type LocalType { get; }

           public virtual bool IsPinned { get; }

           public virtual int LocalIndex { get; }

     }

}

1.2. (System.Reflection.ExceptionHandlingClause


namespace System.Reflection

{

     public sealed class ExceptionHandlingClause

     {

           // This class can only be created from inside the EE.

           private ExceptionHandlingClause() { }



           public ExceptionHandlingClauseFlags Flags { get; }

           public int TryOffset { get; }

           public int TryLength { get; }

           public int HandlerOffset { get; }

           public int HandlerLength { get; }



           public int FilterOffset { get; }

           public Type CatchType { get; }

     }



     public enum ExceptionHandlingClauseFlags : int

     {

           Clause = 0x0,

           Filter = 0x1,

           Finally = 0x2,

           Fault = 0x4,

     }

}



Thanks

Alicia

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.