Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find extern source code for .NET?

Tags:

c#

.net

I wanted to answer this question and thought I would look inside of the Array source code to see how it is implemented. Therefore, I looked in .NET source code for the CreateInstance method and found that it calls an external method whose body is a semi-colon and implemented elsewhere. Here is what it looks like:

private unsafe static extern Array 
    InternalCreate(void* elementType,int rank,int *pLengths,int *pLowerBounds);

Question:

How do I find where the implementation for the above external method is?

like image 557
CodingYoshi Avatar asked Oct 15 '25 03:10

CodingYoshi


1 Answers

To find the source code for any extern methods, do the following:

  1. Find the name of the extern method. In my case it is InternalCreate.
  2. Go here and find the mapping of the method to the external method. In my case I needed to find InternalCreate and here is what the mapping looks like. The name of the class is ArrayNative and the method is CreateInstance:

    FCFuncElement("InternalCreate", ArrayNative::CreateInstance)
    
  3. Find the mapped class here. In my case I needed arraynative and I needed the method CreateInstance. The implementation is right there and I am copying it here but removing the body for brevity:

    FCIMPL4(Object*, ArrayNative::CreateInstance, 
        void* elementTypeHandle, INT32 rank, INT32* pLengths, INT32* pLowerBounds)
    {
        //...
    }
    

There you will find the implementation and study the code.

like image 56
CodingYoshi Avatar answered Oct 18 '25 17:10

CodingYoshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!