// This method will combine this delegate with the passed delegate // to form a new delegate. [System.Security.SecuritySafeCritical] // auto-generated protectedoverridesealed Delegate CombineImpl(Delegate follow) { if ((Object)follow == null) // cast to object for a more efficient test returnthis;
// Verify that the types are the same... if (!InternalEqualTypes(this, follow)) thrownew ArgumentException(Environment.GetResourceString("Arg_DlgtTypeMis"));
MulticastDelegate dFollow = (MulticastDelegate)follow; Object[] resultList; int followCount = 1; Object[] followList = dFollow._invocationList as Object[]; if (followList != null) followCount = (int)dFollow._invocationCount;
int resultCount; Object[] invocationList = _invocationList as Object[]; if (invocationList == null) { resultCount = 1 + followCount; resultList = new Object[resultCount]; resultList[0] = this; if (followList == null) { resultList[1] = dFollow; } else { for (int i = 0; i < followCount; i++) resultList[1 + i] = followList[i]; } return NewMulticastDelegate(resultList, resultCount); } else { int invocationCount = (int)_invocationCount; resultCount = invocationCount + followCount; resultList = null; if (resultCount <= invocationList.Length) { resultList = invocationList; if (followList == null) { if (!TrySetSlot(resultList, invocationCount, dFollow)) resultList = null; } else { for (int i = 0; i < followCount; i++) { if (!TrySetSlot(resultList, invocationCount + i, followList[i])) { resultList = null; break; } } } }
if (resultList == null) { int allocCount = invocationList.Length; while (allocCount < resultCount) allocCount *= 2;
resultList = new Object[allocCount];
for (int i = 0; i < invocationCount; i++) resultList[i] = invocationList[i];
if (followList == null) { resultList[invocationCount] = dFollow; } else { for (int i = 0; i < followCount; i++) resultList[invocationCount + i] = followList[i]; } } return NewMulticastDelegate(resultList, resultCount, true); } }