.net framework collection source code

net2\RefSrc\Source\Net\3.5.50727.3053\DEVDIV\depot\DevDiv\releases\whidbey\netfxsp\ndp\clr\src\BCL\System\Collections

 

 

http://www.projky.com

 

FCIMPL4(Object*, COMArrayInfo::CreateInstance, void* elementTypeHandle, INT32 rank, INT32* pLengths, INT32* pLowerBounds)
{
    CONTRACTL {
        SO_TOLERANT;
        THROWS;
        DISABLED(GC_TRIGGERS);  // reenable once GC_TRIGGERS allowed in FCALLs
        PRECONDITION(rank > 0);
        PRECONDITION(CheckPointer(pLengths));
        PRECONDITION(CheckPointer(pLowerBounds, NULL_OK));
    } CONTRACTL_END;
    OBJECTREF pRet = NULL;
    TypeHandle elementType = TypeHandle::FromPtr(elementTypeHandle);
    _ASSERTE(!elementType.IsNull());
    // pLengths and pLowerBounds are pinned buffers. No need to protect them.
    HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB(Frame::FRAME_ATTR_RETURNOBJ);
    CheckElementType(elementType);
    CorElementType CorType = elementType.GetSignatureCorElementType();
    CorElementType kind = ELEMENT_TYPE_ARRAY;
    // Is it ELEMENT_TYPE_SZARRAY array?
    if (rank == 1 && (pLowerBounds == NULL || pLowerBounds[0] == 0))
    {
        // Shortcut for common cases
        if (CorTypeInfo::IsPrimitiveType(CorType))
        {
            pRet = AllocatePrimitiveArray(CorType,pLengths[0]);
            goto Done;
        }
        else
        if (CorTypeInfo::IsObjRef(CorType))
        {
            pRet = AllocateObjectArray(pLengths[0],elementType);
            goto Done;
        }
        kind = ELEMENT_TYPE_SZARRAY;
        pLowerBounds = NULL;
    }
    {
        // Find the Array class...
        TypeHandle typeHnd = ClassLoader::LoadArrayTypeThrowing(elementType, kind, rank);
        DWORD  boundsSize;
        INT32* bounds;
        if (pLowerBounds != NULL) {
            boundsSize = rank*2;
            bounds = (INT32*) _alloca(boundsSize * sizeof(INT32));
            for (int i=0;i<rank;i++) {
                bounds[2*i] = pLowerBounds[i];
                bounds[2*i+1] = pLengths[i];
            }
        }
        else {
            boundsSize = rank;
            bounds = (INT32*) _alloca(boundsSize * sizeof(INT32));
            // We need to create a private copy of pLengths to avoid holes caused
            // by caller mutating the array
            for (int i=0;i<rank;i++)
                bounds[i] = pLengths[i];
        }
        pRet = AllocateArrayEx(typeHnd, bounds, boundsSize);
    }
Done: ;
    HELPER_METHOD_FRAME_END();
    return OBJECTREFToObject(pRet);
}
FCIMPLEND

 

你可能感兴趣的:(.net framework collection source code)