猿问

“private extern String PadHelper”的源代码在哪里

当我在 .NET 源代码中寻找以下源代码时,我没有找到源代码PadHelper是里面的方法PadLeftPadRight.

我的搜索有问题吗?

[System.Security.SecuritySafeCritical]  // auto-generated

[ResourceExposure(ResourceScope.None)]

[MethodImplAttribute(MethodImplOptions.InternalCall)]

private extern String PadHelper(int totalWidth, char paddingChar, bool isRightPadded);


慕妹3242003
浏览 121回答 1
1回答

一只甜甜圈

这似乎不是一个有据可查的事情。我也不知道更多细节以及它是如何工作的,但是看看CodeProject上的这个线程。该方法似乎位于 comstring.cpp 中。不幸的是,该线程中链接的帖子不再可用。这可能是一个有趣的。编辑:在 github 上找到完整的源代码。/*==================================PadHelper===================================**Action:**Returns:**Arguments:**Exceptions:==============================================================================*/FCIMPL4(Object*, COMString::PadHelper, StringObject* thisRefUNSAFE, INT32 totalWidth, CLR_CHAR paddingChar, CLR_BOOL isRightPadded){&nbsp; &nbsp; CONTRACTL {&nbsp; &nbsp; &nbsp; &nbsp; DISABLED(GC_TRIGGERS);&nbsp; &nbsp; &nbsp; &nbsp; THROWS;&nbsp; &nbsp; &nbsp; &nbsp; MODE_COOPERATIVE;&nbsp; &nbsp; &nbsp; &nbsp; SO_TOLERANT;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; } CONTRACTL_END;&nbsp; &nbsp; STRINGREF refRetVal = NULL;&nbsp; &nbsp; STRINGREF thisRef = (STRINGREF) thisRefUNSAFE;&nbsp; &nbsp; HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(Frame::FRAME_ATTR_RETURNOBJ, thisRef);&nbsp; &nbsp; //-[autocvtpro]-------------------------------------------------------&nbsp; &nbsp; WCHAR *thisChars, *padChars;&nbsp; &nbsp; INT32 thisLength;&nbsp; &nbsp; if (thisRef==NULL) {&nbsp; &nbsp; &nbsp; &nbsp; COMPlusThrow(kNullReferenceException, L"NullReference_This");&nbsp; &nbsp; }&nbsp; &nbsp; RefInterpretGetStringValuesDangerousForGC(thisRef, &thisChars, &thisLength);&nbsp; &nbsp; //Don't let them pass in a negative totalWidth&nbsp; &nbsp; if (totalWidth<0) {&nbsp; &nbsp; &nbsp; &nbsp; COMPlusThrowArgumentOutOfRange(L"totalWidth", L"ArgumentOutOfRange_NeedNonNegNum");&nbsp; &nbsp; }&nbsp; &nbsp; //If the string is longer than the length which they requested, give them&nbsp; &nbsp; //back the old string.&nbsp; &nbsp; if (totalWidth<thisLength) {&nbsp; &nbsp; &nbsp; &nbsp; refRetVal = thisRef;&nbsp; &nbsp; &nbsp; &nbsp; goto lExit;&nbsp; &nbsp; }&nbsp; &nbsp; if (isRightPadded) {&nbsp; &nbsp; &nbsp; &nbsp; refRetVal = NewString(&(thisRef), 0, thisLength, totalWidth);&nbsp; &nbsp; &nbsp; &nbsp; padChars = refRetVal->GetBuffer();&nbsp; &nbsp; &nbsp; &nbsp; for (int i=thisLength; i<totalWidth; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padChars[i] = paddingChar;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; refRetVal->SetStringLength(totalWidth);&nbsp; &nbsp; &nbsp; &nbsp; _ASSERTE(padChars[totalWidth] == 0);&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; refRetVal = NewString(totalWidth);&nbsp; &nbsp; &nbsp; &nbsp; INT32 startingPos = totalWidth-thisLength;&nbsp; &nbsp; &nbsp; &nbsp; padChars = refRetVal->GetBuffer();&nbsp; &nbsp; &nbsp; &nbsp; // Reget thisChars, since if NewString triggers GC, thisChars may become trash.&nbsp; &nbsp; &nbsp; &nbsp; RefInterpretGetStringValuesDangerousForGC(thisRef, &thisChars, &thisLength);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memcpyNoGCRefs(padChars+startingPos, thisChars, thisLength * sizeof(WCHAR));&nbsp; &nbsp; &nbsp; &nbsp; for (int i=0; i<startingPos; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padChars[i] = paddingChar;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }lExit: ;&nbsp; &nbsp; //-[autocvtepi]-------------------------------------------------------&nbsp; &nbsp; HELPER_METHOD_FRAME_END();&nbsp; &nbsp; return OBJECTREFToObject(refRetVal);}FCIMPLEND
随时随地看视频慕课网APP
我要回答