Reflector is a very cool tool that you can use to inspect .NET assemblies. It can decompile IL-code back to C# (at least, it tries to, and a lot of times it doesn't work, but usually it's pretty good at it). I think it's one of the most popular tools for .NET developers. It's like a more advanced version of ILDasm.
2010/1/10 Wee Li Yen <[email protected]> > I didn't see any constant PI value. If I hv seen that I would hv noticed > that. > > I am on Windows... What do u mean by "open that compiled application in > Reflector"? I never used that before. > > I am writing an application using Visual Studio. Nothing wrong with my code > right? > > *From:* Tommy Carlier <[email protected]> > *Sent:* Sunday, January 10, 2010 9:19 PM > *To:* [email protected] > *Subject:* Re: [mono-cecil] Field read and write > > That's right. Try this (if you're on Windows): compile an application that > references a constant (like Math.PI), and open that compiled application in > Reflector. The call the Math.PI will have been replaced by a constant value. > > 2010/1/10 Wee Li Yen <[email protected]> > >> Tommy, so what u mean is there is no way I can detect field read and >> write in this case? >> >> But how come Jb said "So if you want to detect where PI is used, you have >> to check for the `ldc.r8 Math.PI` pattern."? My previous post was trying >> to say that I can't find this. >> >> >> *From:* Tommy Carlier <[email protected]> >> *Sent:* Sunday, January 10, 2010 8:21 PM >> *To:* [email protected] >> *Subject:* Re: [mono-cecil] Field read and write >> >> Because Math.PI is a constant, the compiler will just copy its value to >> the location of where it's used. So, if your code says "double pi = >> Math.PI;", the compiler will translate it to "double pi = 3.1415926...;". >> That's why there are no references to Math.PI. >> >> 2010/1/10 Wee Li Yen <[email protected]> >> >>> Sorry to bother you on this issue again. >>> >>> I print out all the instructions from VisitInstruction (BaseCodeVisitor) >>> in this way: >>> >>> OpCode opCode = instr.OpCode; >>> object operand = instr.Operand; >>> Console.Write("###" + opCode + " " + ((operand != null)? >>> operand.ToString() : "") + "###"); >>> Console.WriteLine(); >>> >>> But I don't see ldc.r8 Math.PI... >>> >>> Do you know why? Thanks... >>> -------------------------------------------------- >>> From: "Jb Evain" <[email protected]> >>> Sent: Friday, January 08, 2010 5:58 PM >>> To: <[email protected]> >>> Subject: Re: [mono-cecil] Field read and write >>> >>> 2010/1/8 Li Yen Wee <[email protected]>: >>>> >>>>> But how has it got to do with me not being able to detect the field >>>>> PIValue >>>>> as written and Math.PI as read? >>>>> >>>> >>>> Again, if you had bothered to investigate a little bit you would know. >>>> PI is defined as a constant, so the compiler will inline its value >>>> everywhere it's used >>>> >>>> var pi = Math.PI is compiled as: >>>> >>>> ldc.r8 3.1415926535897931 >>>> stloc pi >>>> >>>> So if you want to detect where PI is used, you have to check for the >>>> `ldc.r8 Math.PI` pattern. >>>> >>>> -- >>>> Jb Evain <[email protected]> >>>> >>> ------------------------------ > > -- > -- > mono-cecil > > > -- > -- > mono-cecil >
-- -- mono-cecil
