Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 201939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:14:35+00:00 2026-05-11T17:14:35+00:00

I have several special methods, and I want analyze they calls in compiled assembly.

  • 0

I have several special methods, and I want analyze they calls in compiled assembly.

Example:

public static class SrcHelper {
    [MySpecialMethod]
    [Conditional( "DEBUG" )]
    public static void ToDo( params object[] info ) {
        /* do nothing */
        /* this method is not called when code is compiled in RELEASE mode */
    }
}
// ... somewhere else in another assembly ...
Array CreateArraySampleMethod( int size ) {
    // This call has only informative character. No functionality is required.
    SrcHelper.ToDo( "Should create array of ", typeof( MyClass ), " with specified size." );
    throw new NotImplementedException();
}

From this compiled code I want get the argument values { “Should create array of “, MyClass, ” with specified size.” }.
I tried use Cecil from Mono, and I found the instructions for call “ToDo” method. But now am I confused how to identify instruction with argument values.

I know, there can be complex situation, and some argument’s value can not be resolved. But I need resolve only constant values – it’s enough for my purpose.

Thanks.

EDIT:
The “ToDo” method (and similar ones) should be used as alternative to comments ( //, /* … */ ), and after compilation, should be IL analyzed and autogenerated documentation and todo-list for concrete assembly.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:14:36+00:00Added an answer on May 11, 2026 at 5:14 pm

    The code generation is somewhat confusing but can be done for simple cases:

    compiling:

    public static void Main(string[] args)
    {
        Console.WriteLine("", // ignore this argument
           "Should create array of ", typeof(int), " with specified size." "x");
    }
    

    (adding "x" to force it to use a params overload)

    gives

    .method public hidebysig static void Main(string[] args) cil managed
    {
        .custom instance void [mscorlib]System.STAThreadAttribute::.ctor()
        .maxstack 4
        .locals init (
            [0] object[] objArray)
        L_0000: ldstr ""
        L_0005: ldc.i4.4 
        L_0006: newarr object
        L_000b: stloc.0 
        L_000c: ldloc.0 
        L_000d: ldc.i4.0 
        L_000e: ldstr "Should create array of "
        L_0013: stelem.ref 
        L_0014: ldloc.0 
        L_0015: ldc.i4.1 
        L_0016: ldtoken int32
        L_001b: call class [mscorlib]System.Type 
                    [mscorlib]System.Type::GetTypeFromHandle(
                        valuetype [mscorlib]System.RuntimeTypeHandle)
        L_0020: stelem.ref 
        L_0021: ldloc.0 
        L_0022: ldc.i4.2 
        L_0023: ldstr " with specified size."
        L_0028: stelem.ref 
        L_0029: ldloc.0 
        L_002a: ldc.i4.3 
        L_002b: ldstr "x"
        L_0030: stelem.ref 
        L_0031: ldloc.0 
        L_0032: call void [mscorlib]System.Console::WriteLine(string, object[])
        L_0037: ret 
    }
    

    So you have to do is parse the il to detect the arguments being pushed into the compiler generated array. a heristic that is fragile but might be sufficient it to say:

    1. find call to ‘my method’.
    2. find nearest previous newarr object
    3. take all ldstr and ldtoken in between these and assume they are the arguments.

    This is rough but may be sufficient for your needs.

    An AOP style approach will get you what you want at runtime by simply instrumenting every call to dump the values but at sompile time the approach above is your only realistic option given only the IL.

    The code generated may be very different in Release builds, You will be unable to spot the auto generated array verses someone explicitly creating it themselves (which may be further away from the call site or even in a different method/constructor/class.

    Proviso

    I should note after your edit for why you want to do this that Attribute based annotations are a far better solution, I cannot see why you would want to do this in the method when you can attribute it directly…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several nested enums similar to the following. I want to have an
I have several models grouped in a module like this: #/app/models/blobs/small_text.rb class Blobs::SmallText <
I have an abstract class A and several implementations of it. I expect this
I have several flag-like enumerations, in C++. For example: enum some_state { state_normal =
Probably a very newb C++ question. Say I have a class, vertex, with several
I want to give access to protected properties to another class. I have been
Suppose I have this model: public class ViewModel { [Required] public string UserInput {
I have a Form with several special controls on it that is the main
I have several lines of property definitions, e.g.: public InputProp<string CsProtocol { private get;
In HTML, there are several special characters < > & ' which have significance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.