How to find extern source code for .NET?

时间:2017-04-24 17:26:27

标签: 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?

1 个答案:

答案 0 :(得分:3)

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.