Decompile .NET Replace Method (v4.6.1)

I want to see how

public String Replace(String oldValue, String newValue); 

which is inside mscorlib.dll (System.String).

I decompiled mscorlib.dll using dotPeek, and inside the method there is a call to the ReplaceInternal method that I cannot find

 string s = ReplaceInternal(oldValue, newValue); 

I am looking for this method even in .NET with open source from GIT, but no luck.

View my decompiled code

Please explain where is this method and what's inside?

+6
source share
3 answers

The external C ++ code is here.

https://github.com/gbarnett/shared-source-cli-2.0/blob/master/clr/src/vm/comstring.cpp

Line 1578 has

 FCIMPL3(Object*, COMString::ReplaceString, StringObject* thisRefUNSAFE, StringObject* oldValueUNSAFE, StringObject* newValueUNSAFE) 
+4
source

Looking here , you will notice the following:

 // This method contains the same functionality as StringBuilder Replace. // The only difference is that // a new String has to be allocated since Strings are immutable [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern String ReplaceInternal(String oldValue, String newValue); 

The extern keyword means that this method is implemented externally in another dll.

Moreover, it can even be written in an uncontrolled dll (possibly in C ++), which is used by this module. Thus, you cannot decompile this code or see it, as usual, with managed code.

Update

After a short search, I found the appropriate code in the coreclr project:

https://github.com/dotnet/coreclr/blob/master/src/classlibnative/bcltype/stringnative.cpp

+4
source

To find out how the function works, look at the link source at http://referencesource.microsoft.com/ .

Serach for mscorlib , go to System.String , serach for Replace and look: http://referencesource.microsoft.com/#mscorlib/system/string.cs,6.69fc1d0aa6df8a90,references

0
source

All Articles