???????????忴???Remove()??????????????RemoveAll??Remove?????????System.Delegate?????У?CombineImpl??????MulticastDelegate??д????
public static Delegate RemoveAll(Delegate source?? Delegate value)
{
Delegate newDelegate = null;
do
{
newDelegate = source;
source = Remove(source?? value);
}
while (newDelegate != source);
return newDelegate;
}
[System.Security.SecuritySafeCritical]
public static Delegate Remove(Delegate source?? Delegate value)
{
if (source == null)
return null;
if (value == null)
return source;
if (!InternalEqualTypes(source?? value))
throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTypeMis"));
return source.RemoveImpl(value);
}
[System.Security.SecuritySafeCritical]
protected override sealed Delegate RemoveImpl(Delegate value)
{             MulticastDelegate v = value as MulticastDelegate;
if (v == null)
return this;
if (v._invocationList as Object[] == null)
{
Object[] invocationList = _invocationList as Object[];
if (invocationList == null)
{
if (this.Equals(value))
return null;
}
else
{
int invocationCount = (int)_invocationCount;
for (int i = invocationCount; --i >= 0; )
{
if (value.Equals(invocationList[i]))
{
if (invocationCount == 2)
{
return (Delegate)invocationList[1-i];
}
else
{
Object[] list = DeleteFromInvocationList(invocationList?? invocationCount?? i?? 1);
return NewMulticastDelegate(list?? invocationCount-1?? true);
}
}
}
}
}
else
{
Object[] invocationList = _invocationList as Object[];
if (invocationList != null) {
int invocationCount = (int)_invocationCount;
int vInvocationCount = (int)v._invocationCount;
for (int i = invocationCount - vInvocationCount; i >= 0; i--)
{
if (EqualInvocationLists(invocationList?? v._invocationList as Object[]?? i?? vInvocationCount))
{
if (invocationCount - vInvocationCount == 0)
{
return null;
}
else if (invocationCount - vInvocationCount == 1)
{
return (Delegate)invocationList[i != 0 ? 0 : invocationCount-1];
}
else
{
Object[] list = DeleteFromInvocationList(invocationList?? invocationCount?? i?? vInvocationCount);
return NewMulticastDelegate(list?? invocationCount - vInvocationCount?? true);
}
}
}
}
}
return this;
}
???????????????У????????????.NET?????????????????????????????
?????????????????????е?????????????е????????t????????void??????????????????????????????????????????????б????κβ???????????????????к??????????
??????????????????б??г????void??????????????????г???????void??????????????????е??????????????????????????β???????.NET?????????????GetInvocationList()????????????????
????????????????????GetInvocationList()???????
[System.Security.SecuritySafeCritical]
public override sealed Delegate[] GetInvocationList()
{
Delegate[] del;
Object[] invocationList = _invocationList as Object[];
if (invocationList == null)
{
del = new Delegate[1];
del[0] = this;
}
else
{
int invocationCount = (int)_invocationCount;
del = new Delegate[invocationCount];
for (int i = 0; i < invocationCount; i++)
del[i] = (Delegate)invocationList[i];
}
return del;
}
??????????????????б???????????????????????λ???????????????????
??????????????????Method?????忴??′??????????????
public MethodInfo Method
{
get
{
return GetMethodImpl();
}
}
[System.Security.SecuritySafeCritical]
protected virtual MethodInfo GetMethodImpl()
{
if ((_methodBase == null) || !(_methodBase is MethodInfo))
{
IRuntimeMethodInfo method = FindMethodHandle();
RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(method);
if (RuntimeTypeHandle.IsGenericTypeDefinition(declaringType) || RuntimeTypeHandle.HasInstantiation(declaringType))
{
bool isStatic = (RuntimeMethodHandle.GetAttributes(method) & MethodAttributes.Static) != (MethodAttributes)0;
if (!isStatic)
{
if (_methodPtrAux == (IntPtr)0)
{
Type currentType = _target.GetType();
Type targetType = declaringType.GetGenericTypeDefinition();
while (currentType != null)
{
if (currentType.IsGenericType &&
currentType.GetGenericTypeDefinition() == targetType)
{
declaringType = currentType as RuntimeType;
break;
}
currentType = currentType.BaseType;
}
BCLDebug.Assert(currentType != null || _target.GetType().IsCOMObject?? "The class hierarchy should declare the method");
}
else
{
MethodInfo invoke = this.GetType().GetMethod("Invoke");
declaringType = (RuntimeType)invoke.GetParameters()[0].ParameterType;
}
}
}
_methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType?? method);
}
return (MethodInfo)_methodBase;
}
??????????System.Delegate???е???壬???????????MulticastDelegate??д??
[System.Security.SecuritySafeCritical]
protected override MethodInfo GetMethodImpl()
{
if (_invocationCount != (IntPtr)0 && _invocationList != null)
{
Object[] invocationList = _invocationList as Object[];
if (invocationList != null)
{
int index = (int)_invocationCount - 1;
return ((Delegate)invocationList[index]).Method;
}
MulticastDelegate innerDelegate = _invocationList as MulticastDelegate;
if (innerDelegate != null)
{
return innerDelegate.GetMethodImpl();
}
}
else if (IsUnmanagedFunctionPtr())
{
if ((_methodBase == null) || !(_methodBase is MethodInfo))
{
IRuntimeMethodInfo method = FindMethodHandle();
RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(method);
if (RuntimeTypeHandle.IsGenericTypeDefinition(declaringType) || RuntimeTypeHandle.HasInstantiation(declaringType))
{
RuntimeType reflectedType = GetType() as RuntimeType;
declaringType = reflectedType;
}
_methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType?? method);
}
return (MethodInfo)_methodBase;
}
return base.GetMethodImpl();
}
?????????????е??????壬????й???е??Щ?????????????????о?????????????????????У??????е???????????????????????????????????????????????????????C#???????????????????????????????????????????????????ò??????????????????????????????????????????