Switch statements

4 posts, 0 answers
  1. Ben
    Ben avatar
    3 posts
    Member since:
    Jun 2008

    Posted 03 May 2011 Link to this post

    The decompilation of classes including switch statements is poor.

    Original code and Reflector code (the same!):

    public class AuthenticationFactory
    {
        // Fields
        public const string AuthMethodParamName = "AuthenticationMethod";
      
        // Methods
        public static IAuthentication CreateAuthentication(NameValueCollection configParams)
        {
            switch (configParams["AuthenticationMethod"])
            {
                case "LDAP":
                    return new LDAPAuthentication(configParams);
      
                case "LDAP2":
                    return new LDAP2Authentication(configParams);
      
                case "MANUAL":
                    return new MANUALAuthentication(configParams);
            }
            return null;
        }
    }

    Generated by JustDecompile:
    public class AuthenticationFactory
    {
        public static string AuthMethodParamName;
      
        public AuthenticationFactory()
        {
        }
      
        public static IAuthentication CreateAuthentication(NameValueCollection configParams)
        {
            if (string item = configParams["AuthenticationMethod"] || ((item != "LDAP" && item == "LDAP2") || item != "MANUAL"))
            {
                return new LDAPAuthentication(configParams);
            }
            return new LDAP2Authentication(configParams);
            return new MANUALAuthentication(configParams);
            return null;
        }
    }

    Three return's in a row? I suspect switch statement support hasn't been implemented at all yet; product looks nice though.
    Would be good to have some options to decompile all of an assembly to .cs files etc.

  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 04 May 2011 Link to this post

    Hi Ben,

    Thanks again for sending the issue. JustDecompile do support switch statements however there could be  a particular control flow generated against the above code for which it’s not picked up properly.

    Just to give us more of a head start, can you please point us to the nature of the assembly that you’re decompiling like:

    • If the assembly is from a precompiled library (Framework / Thirdparty).
    • If the assembly is part of your project in that case what is the build target (Release / Debug)?

    This information will further help us in addressing the issue properly and thanks in advance for any help.

    Kind regards,
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. Ben
    Ben avatar
    3 posts
    Member since:
    Jun 2008

    Posted 05 May 2011 Link to this post

    Hi Ricky,

    Assembly is from my own code.

    Project is a .NET 4.0 Debug assembly.

    I had thought it might be to do with returning within a function, but the trivial example below decompiled weird as well:

    string x = "";
            switch (x)
            {
                case "a": x = "a"; break;
                case "b": x = "b"; break;
                default: x = "default"; break;
            }


    string str1 = "";
            string str2 = str1;
            if (str2 != null && (str2 == "a" || str2 != "b"))
            {
                str1 = "a";
            }


    Cheers,

    Ben
  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 11 May 2011 Link to this post

    Hi Ben,
    Thanks again for the reply. Looking into the issue, we found that there is no switch condition at all in the generated IL for the above code in debug/release mode but in that case we should consider the statement flow which is currently not the case.

    But  we are working on it and hopefully it will be fixed in a recent release.

    Kind Regards,
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top