问题描述
在使用反射拆卸净源$ C $ C,我来到了对象类的Equals实现,它指的是
While disassembling the .Net Source Code using Reflector, I came upon the Equals implementation in the Object Class and it refers to
bool InternalEquals(object objA, object objB);
这又是指
internal static extern bool InternalEquals(object objA, object objB);
我现在的困惑就在哪里可以找到这种 InternalEquals(对象objA,反对objB)
功能以及如何使用此功能,并在.NET程序集执行它在该功能定义并且如果每一切都从头开始编写的.NET源$ C $ C,那么为什么我无法找到该功能的实现。
I am now confused regarding where to find the implementation of this InternalEquals(object objA, object objB)
function and how is it using this function and in which .Net assembly is this function defined and also if each and everything is written from scratch for the .Net Source Code, then why am I unable to find this function's implementation.
推荐答案
它的声明为 [MethodImpl(MethodImplOptions.InternalCall)]
。这意味着,它在CLR本身实现的,作为本机的过程,而不是一个.NET程序集。
It's declared as [MethodImpl(MethodImplOptions.InternalCall)]
. It means that it's implemented in the CLR itself, as a native procedure, not a .NET assembly.
您可以通过查看<视图类似的CLR源$ C $ C href="http://www.microsoft.com/downloads/details.aspx?FamilyId=8C09FD61-3F26-4555-AE17-3121B4F51D4D&displaylang=en"相对=nofollow>微软SSCLI(即转子)。
在SSCLI 2.0它实现为(以 sscli20 / CLR / src目录/ VM / comobject.cpp
):
In SSCLI 2.0 it's implemented as (in sscli20/clr/src/vm/comobject.cpp
):
FCIMPL2(FC_BOOL_RET, ObjectNative::Equals, Object *pThisRef, Object *pCompareRef)
{
CONTRACTL
{
THROWS;
DISABLED(GC_NOTRIGGER);
INJECT_FAULT(FCThrow(kOutOfMemoryException););
MODE_COOPERATIVE;
SO_TOLERANT;
}
CONTRACTL_END;
if (pThisRef == pCompareRef)
FC_RETURN_BOOL(TRUE);
// Since we are in FCALL, we must handle NULL specially.
if (pThisRef == NULL || pCompareRef == NULL)
FC_RETURN_BOOL(FALSE);
MethodTable *pThisMT = pThisRef->GetMethodTable();
// If it's not a value class, don't compare by value
if (!pThisMT->IsValueClass())
FC_RETURN_BOOL(FALSE);
// Make sure they are the same type.
if (pThisMT != pCompareRef->GetMethodTable())
FC_RETURN_BOOL(FALSE);
// Compare the contents (size - vtable - sink block index).
BOOL ret = memcmp(
(void *) (pThisRef+1),
(void *) (pCompareRef+1),
pThisRef->GetMethodTable()->GetBaseSize() - sizeof(Object) - sizeof(int)) == 0;
FC_GC_POLL_RET();
FC_RETURN_BOOL(ret);
}
FCIMPLEND
这篇关于哪里是InternalEquals(对象objA,对象objB)的实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!