(NTH) Handling of optional parameters

3 posts, 0 answers
  1. Holger Boskugel
    Holger Boskugel avatar
    27 posts
    Member since:
    Apr 2012

    Posted 09 Dec 2017 Link to this post

    It's a nice to have feature, as your decompilation is quite correct.

    If there is a method with optional parameters

    void MyMethod(string myStringParameter, bool myOptionalParameter1 = true, bool myOptionalParameter2 = true)

    you decompile it with the full set of parameter values

    MyMethod("MyString", true, true);

    but original code had been


    as the both "true" values are defaults for the optional parameters.

    It would be nice to get the "original" code instead the full parametrised method like your current decompilation,

  2. Alexander
    Alexander avatar
    383 posts

    Posted 02 Jan 2018 Link to this post


    Retrieving the original code is impossible in most cases. JustDecompile's target is to produce equivalent valid code to that which was used to compile the assembly, not 1:1 to the original code.

    In this case the optional parameters are syntax sugar and the compiler produces method invocations with all parameters. It seems possible to reduce the parameters to only the non-optional and/or with different value than the default one, but there is no guarantee that this code will match the original code, since you can still pass the default value to optional parameter.

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Holger Boskugel
    Holger Boskugel avatar
    27 posts
    Member since:
    Apr 2012

    Posted 28 Jan 2018 in reply to Alexander Link to this post


    you have the possibility to reduce that parameters on decompile. As we see you know the method signature with optional parameters which get decompiled right. So a call to this method can be reduced, starting from last argument and stop with the first non matching default value.


    See it at the sample above. You know myOptionalParameter1 and myOptionalParameter2 have default values and those values are true. The call you find is with a string and two boolean of true. So starting from this the signature of string, boolean, boolean is to use. There you find the booleans are optional starting from last myOptionalParameter2 is true and myOptionalParameter2 has a default value of true, so this parameter can ignored, same for myOptionalParameter1. So call reducable to only string.




Back to Top