"PrivateImplementationDetails" function when decompiling a C #

11,006

At the time the question was asked, the generated IL was relatively new, so the decompilers hadn't been updated to support it. Essentially the decompiler revealed some of the underlying .NET framework code and the hash function used to support string switch statements.

Now, a year or so later, the decompilers have been updated so they should just show a switch statement like this:

switch (sss)
{
    case "ASD":
    // do something
    break;
    case "JKL":
    // do something
    break
}

I've tested this with DotPeek and can confirm it shows this correctly.

Share:
11,006
Joseph
Author by

Joseph

Updated on June 04, 2022

Comments

  • Joseph
    Joseph almost 2 years

    I'm rebuilding a library programmed in C # and need help with a Switch statement, I have the following code snippet using the <PrivateImplementationDetails> .ComputeStringHash () function generated during compilation. My question is, what is the function that I should use? Will I get the same result using sss.GetHashCode()?

    Currently the error that is presented to me is Can not resolve symbol 'PrivateImplementationDetails'.

     switch (<PrivateImplementationDetails>.ComputeStringHash(sss)) {
        case 0x1315fc:
            if (sss == "ASD") {
                break;
            }
            goto Label_0105;
    
        case 0x15c3dc:
            if (sss == "JKL") {
                break;
            }
            goto Label_0105;
     }