summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/MulticastDelegate.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
commita56e30c8d33048216567753d9d3fefc2152af8ac (patch)
tree7e5d979695fc4a431740982eb1cfecc2898b23a5 /src/mscorlib/src/System/MulticastDelegate.cs
parent4b11dc566a5bbfa1378d6266525c281b028abcc8 (diff)
downloadcoreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.gz
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.bz2
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.zip
Imported Upstream version 2.0.0.11353upstream/2.0.0.11353
Diffstat (limited to 'src/mscorlib/src/System/MulticastDelegate.cs')
-rw-r--r--src/mscorlib/src/System/MulticastDelegate.cs176
1 files changed, 88 insertions, 88 deletions
diff --git a/src/mscorlib/src/System/MulticastDelegate.cs b/src/mscorlib/src/System/MulticastDelegate.cs
index aa3271ceab..440c9a60bc 100644
--- a/src/mscorlib/src/System/MulticastDelegate.cs
+++ b/src/mscorlib/src/System/MulticastDelegate.cs
@@ -2,17 +2,17 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
+using System.Reflection;
+using System.Runtime;
+using System.Runtime.CompilerServices;
+using System.Runtime.Serialization;
+using System.Diagnostics;
+using System.Diagnostics.Contracts;
+using System.Reflection.Emit;
+
namespace System
{
- using System;
- using System.Reflection;
- using System.Runtime;
- using System.Runtime.CompilerServices;
- using System.Runtime.Serialization;
- using System.Diagnostics;
- using System.Diagnostics.Contracts;
- using System.Reflection.Emit;
-
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class MulticastDelegate : Delegate
@@ -21,8 +21,8 @@ namespace System
// 1. Multicast delegate
// 2. Secure/Wrapper delegate
// 3. Inner delegate of secure delegate where the secure delegate security context is a collectible method
- private Object _invocationList;
- private IntPtr _invocationCount;
+ private Object _invocationList;
+ private IntPtr _invocationCount;
// This constructor is called from the class generated by the
// compiler generated code (This must match the constructor
@@ -30,11 +30,11 @@ namespace System
protected MulticastDelegate(Object target, String method) : base(target, method)
{
}
-
+
// This constructor is called from a class to generate a
// delegate based upon a static method name and the Type object
// for the class defining the method.
- protected MulticastDelegate(Type target, String method) : base(target, method)
+ protected MulticastDelegate(Type target, String method) : base(target, method)
{
}
@@ -58,25 +58,25 @@ namespace System
// A MethodInfo object can be a RuntimeMethodInfo, a RefEmit method (MethodBuilder, etc), or a DynamicMethod
// One can only create delegates on RuntimeMethodInfo and DynamicMethod.
// If it is not a RuntimeMethodInfo (must be a DynamicMethod) or if it is an unmanaged function pointer, throw
- if ( !(method is RuntimeMethodInfo) || IsUnmanagedFunctionPtr() )
- throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType"));
+ if (!(method is RuntimeMethodInfo) || IsUnmanagedFunctionPtr())
+ throw new SerializationException(SR.Serialization_InvalidDelegateType);
// We can't deal with secure delegates either.
if (!InvocationListLogicallyNull() && !_invocationCount.IsNull() && !_methodPtrAux.IsNull())
- throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType"));
+ throw new SerializationException(SR.Serialization_InvalidDelegateType);
- DelegateSerializationHolder.GetDelegateSerializationInfo(info, this.GetType(), Target, method, targetIndex);
+ DelegateSerializationHolder.GetDelegateSerializationInfo(info, this.GetType(), Target, method, targetIndex);
}
else
{
DelegateSerializationHolder.DelegateEntry nextDe = null;
int invocationCount = (int)_invocationCount;
- for (int i = invocationCount; --i >= 0; )
+ for (int i = invocationCount; --i >= 0;)
{
MulticastDelegate d = (MulticastDelegate)invocationList[i];
MethodInfo method = d.Method;
// If it is not a RuntimeMethodInfo (must be a DynamicMethod) or if it is an unmanaged function pointer, skip
- if ( !(method is RuntimeMethodInfo) || IsUnmanagedFunctionPtr() )
+ if (!(method is RuntimeMethodInfo) || IsUnmanagedFunctionPtr())
continue;
// We can't deal with secure delegates either.
@@ -86,12 +86,12 @@ namespace System
DelegateSerializationHolder.DelegateEntry de = DelegateSerializationHolder.GetDelegateSerializationInfo(info, d.GetType(), d.Target, method, targetIndex++);
if (nextDe != null)
nextDe.Entry = de;
-
+
nextDe = de;
}
// if nothing was serialized it is a delegate over a DynamicMethod, so just throw
- if (nextDe == null)
- throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType"));
+ if (nextDe == null)
+ throw new SerializationException(SR.Serialization_InvalidDelegateType);
}
}
@@ -105,14 +105,14 @@ namespace System
return true;
if (!InternalEqualTypes(this, obj))
return false;
-
+
// Since this is a MulticastDelegate and we know
// the types are the same, obj should also be a
// MulticastDelegate
Debug.Assert(obj is MulticastDelegate, "Shouldn't have failed here since we already checked the types are the same!");
var d = JitHelpers.UnsafeCast<MulticastDelegate>(obj);
- if (_invocationCount != (IntPtr)0)
+ if (_invocationCount != (IntPtr)0)
{
// there are 4 kind of delegate kinds that fall into this bucket
// 1- Multicast (_invocationList is Object[])
@@ -134,17 +134,17 @@ namespace System
if ((d._invocationList as Delegate) != null)
// this is a secure/wrapper delegate so we need to unwrap and check the inner one
return Equals(d._invocationList);
-
+
return base.Equals(obj);
}
else
{
- if ((_invocationList as Delegate) != null)
+ if ((_invocationList as Delegate) != null)
{
// this is a secure/wrapper delegate so we need to unwrap and check the inner one
- return _invocationList.Equals(obj);
+ return _invocationList.Equals(obj);
}
- else
+ else
{
Debug.Assert((_invocationList as Object[]) != null, "empty invocation list on multicast delegate");
return InvocationListEquals(d);
@@ -159,11 +159,11 @@ namespace System
// and call the base.Equals()
if (!InvocationListLogicallyNull())
{
- if (!_invocationList.Equals(d._invocationList))
+ if (!_invocationList.Equals(d._invocationList))
return false;
return base.Equals(d);
}
-
+
// now we know 'this' is not a special one, so we can work out what the other is
if ((d._invocationList as Delegate) != null)
// this is a secure/wrapper delegate so we need to unwrap and check the inner one
@@ -173,7 +173,7 @@ namespace System
return base.Equals(d);
}
}
-
+
// Recursive function which will check for equality of the invocation list.
private bool InvocationListEquals(MulticastDelegate d)
{
@@ -181,7 +181,7 @@ namespace System
Object[] invocationList = _invocationList as Object[];
if (d._invocationCount != _invocationCount)
return false;
-
+
int invocationCount = (int)_invocationCount;
for (int i = 0; i < invocationCount; i++)
{
@@ -197,16 +197,16 @@ namespace System
{
if (a[index] == null && System.Threading.Interlocked.CompareExchange<Object>(ref a[index], o, null) == null)
return true;
-
+
// The slot may be already set because we have added and removed the same method before.
// Optimize this case, because it's cheaper than copying the array.
if (a[index] != null)
{
- MulticastDelegate d = (MulticastDelegate)o;
+ MulticastDelegate d = (MulticastDelegate)o;
MulticastDelegate dd = (MulticastDelegate)a[index];
-
- if (dd._methodPtr == d._methodPtr &&
- dd._target == d._target &&
+
+ if (dd._methodPtr == d._methodPtr &&
+ dd._target == d._target &&
dd._methodPtrAux == d._methodPtrAux)
{
return true;
@@ -224,12 +224,12 @@ namespace System
// copy _methodPtr and _methodPtrAux fields rather than calling into the EE to get them
if (thisIsMultiCastAlready)
{
- result._methodPtr = this._methodPtr;
+ result._methodPtr = this._methodPtr;
result._methodPtrAux = this._methodPtrAux;
}
else
{
- result._methodPtr = GetMulticastInvoke();
+ result._methodPtr = GetMulticastInvoke();
result._methodPtrAux = GetInvokeMethod();
}
result._target = result;
@@ -244,17 +244,16 @@ namespace System
return NewMulticastDelegate(invocationList, invocationCount, false);
}
- internal void StoreDynamicMethod(MethodInfo dynamicMethod)
+ internal void StoreDynamicMethod(MethodInfo dynamicMethod)
{
- if (_invocationCount != (IntPtr)0)
+ if (_invocationCount != (IntPtr)0)
{
Debug.Assert(!IsUnmanagedFunctionPtr(), "dynamic method and unmanaged fntptr delegate combined");
// must be a secure/wrapper one, unwrap and save
MulticastDelegate d = (MulticastDelegate)_invocationList;
d._methodBase = dynamicMethod;
-
}
- else
+ else
_methodBase = dynamicMethod;
}
@@ -267,15 +266,15 @@ namespace System
// Verify that the types are the same...
if (!InternalEqualTypes(this, follow))
- throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTypeMis"));
+ throw new ArgumentException(SR.Arg_DlgtTypeMis);
MulticastDelegate dFollow = (MulticastDelegate)follow;
Object[] resultList;
int followCount = 1;
Object[] followList = dFollow._invocationList as Object[];
if (followList != null)
- followCount = (int)dFollow._invocationCount;
-
+ followCount = (int)dFollow._invocationCount;
+
int resultCount;
Object[] invocationList = _invocationList as Object[];
if (invocationList == null)
@@ -325,12 +324,12 @@ namespace System
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;
@@ -344,22 +343,22 @@ namespace System
return NewMulticastDelegate(resultList, resultCount, true);
}
}
-
+
private Object[] DeleteFromInvocationList(Object[] invocationList, int invocationCount, int deleteIndex, int deleteCount)
{
Object[] thisInvocationList = _invocationList as Object[];
int allocCount = thisInvocationList.Length;
- while (allocCount/2 >= invocationCount - deleteCount)
+ while (allocCount / 2 >= invocationCount - deleteCount)
allocCount /= 2;
-
+
Object[] newInvocationList = new Object[allocCount];
-
+
for (int i = 0; i < deleteIndex; i++)
newInvocationList[i] = invocationList[i];
-
+
for (int i = deleteIndex + deleteCount; i < invocationCount; i++)
newInvocationList[i - deleteCount] = invocationList[i];
-
+
return newInvocationList;
}
@@ -384,8 +383,8 @@ namespace System
// the value we need to check for this case
//
MulticastDelegate v = value as MulticastDelegate;
-
- if (v == null)
+
+ if (v == null)
return this;
if (v._invocationList as Object[] == null)
{
@@ -399,19 +398,19 @@ namespace System
else
{
int invocationCount = (int)_invocationCount;
- for (int i = invocationCount; --i >= 0; )
+ for (int i = invocationCount; --i >= 0;)
{
if (value.Equals(invocationList[i]))
{
if (invocationCount == 2)
{
// Special case - only one value left, either at the beginning or the end
- return (Delegate)invocationList[1-i];
+ return (Delegate)invocationList[1 - i];
}
else
{
Object[] list = DeleteFromInvocationList(invocationList, invocationCount, i, 1);
- return NewMulticastDelegate(list, invocationCount-1, true);
+ return NewMulticastDelegate(list, invocationCount - 1, true);
}
}
}
@@ -420,7 +419,8 @@ namespace System
else
{
Object[] invocationList = _invocationList as Object[];
- if (invocationList != null) {
+ if (invocationList != null)
+ {
int invocationCount = (int)_invocationCount;
int vInvocationCount = (int)v._invocationCount;
for (int i = invocationCount - vInvocationCount; i >= 0; i--)
@@ -435,7 +435,7 @@ namespace System
else if (invocationCount - vInvocationCount == 1)
{
// Special case - only one value left, either at the beginning or the end
- return (Delegate)invocationList[i != 0 ? 0 : invocationCount-1];
+ return (Delegate)invocationList[i != 0 ? 0 : invocationCount - 1];
}
else
{
@@ -446,7 +446,7 @@ namespace System
}
}
}
-
+
return this;
}
@@ -467,7 +467,7 @@ namespace System
// Create an array of delegate copies and each
// element into the array
del = new Delegate[(int)_invocationCount];
-
+
for (int i = 0; i < del.Length; i++)
del[i] = (Delegate)invocationList[i];
}
@@ -478,7 +478,7 @@ namespace System
{
if ((Object)d1 == null)
return (Object)d2 == null;
-
+
return d1.Equals(d2);
}
@@ -486,10 +486,10 @@ namespace System
{
if ((Object)d1 == null)
return (Object)d2 != null;
-
+
return !d1.Equals(d2);
}
-
+
public override sealed int GetHashCode()
{
if (IsUnmanagedFunctionPtr())
@@ -505,16 +505,16 @@ namespace System
int hash = 0;
for (int i = 0; i < (int)_invocationCount; i++)
{
- hash = hash*33 + invocationList[i].GetHashCode();
+ hash = hash * 33 + invocationList[i].GetHashCode();
}
-
+
return hash;
}
}
internal override Object GetTarget()
{
- if (_invocationCount != (IntPtr)0)
+ if (_invocationCount != (IntPtr)0)
{
// _invocationCount != 0 we are in one of these cases:
// - Multicast -> return the target of the last delegate in the list
@@ -529,7 +529,7 @@ namespace System
else
{
Object[] invocationList = _invocationList as Object[];
- if (invocationList != null)
+ if (invocationList != null)
{
int invocationCount = (int)_invocationCount;
return ((Delegate)invocationList[invocationCount - 1]).GetTarget();
@@ -537,7 +537,7 @@ namespace System
else
{
Delegate receiver = _invocationList as Delegate;
- if (receiver != null)
+ if (receiver != null)
return receiver.GetTarget();
}
}
@@ -587,18 +587,18 @@ namespace System
// Otherwise, must be an inner delegate of a SecureDelegate of an open virtual method. In that case, call base implementation
return base.GetMethodImpl();
}
-
+
// this should help inlining
[System.Diagnostics.DebuggerNonUserCode]
- private void ThrowNullThisInDelegateToInstance()
+ private void ThrowNullThisInDelegateToInstance()
{
- throw new ArgumentException(Environment.GetResourceString("Arg_DlgtNullInst"));
+ throw new ArgumentException(SR.Arg_DlgtNullInst);
}
[System.Diagnostics.DebuggerNonUserCode]
private void CtorClosed(Object target, IntPtr methodPtr)
{
- if (target == null)
+ if (target == null)
ThrowNullThisInDelegateToInstance();
this._target = target;
this._methodPtr = methodPtr;
@@ -631,35 +631,35 @@ namespace System
{
MulticastDelegate realDelegate = (MulticastDelegate)Delegate.InternalAllocLike(this);
realDelegate.CtorClosed(target, methodPtr);
- this._invocationList = realDelegate;
+ _invocationList = realDelegate;
this._target = this;
this._methodPtr = callThunk;
this._methodPtrAux = creatorMethod;
- this._invocationCount = GetInvokeMethod();
+ _invocationCount = GetInvokeMethod();
}
-
+
[System.Diagnostics.DebuggerNonUserCode]
private void CtorSecureClosedStatic(Object target, IntPtr methodPtr, IntPtr callThunk, IntPtr creatorMethod)
{
MulticastDelegate realDelegate = (MulticastDelegate)Delegate.InternalAllocLike(this);
realDelegate.CtorClosedStatic(target, methodPtr);
- this._invocationList = realDelegate;
+ _invocationList = realDelegate;
this._target = this;
this._methodPtr = callThunk;
this._methodPtrAux = creatorMethod;
- this._invocationCount = GetInvokeMethod();
+ _invocationCount = GetInvokeMethod();
}
-
+
[System.Diagnostics.DebuggerNonUserCode]
private void CtorSecureRTClosed(Object target, IntPtr methodPtr, IntPtr callThunk, IntPtr creatorMethod)
{
MulticastDelegate realDelegate = Delegate.InternalAllocLike(this);
realDelegate.CtorRTClosed(target, methodPtr);
- this._invocationList = realDelegate;
+ _invocationList = realDelegate;
this._target = this;
this._methodPtr = callThunk;
this._methodPtrAux = creatorMethod;
- this._invocationCount = GetInvokeMethod();
+ _invocationCount = GetInvokeMethod();
}
[System.Diagnostics.DebuggerNonUserCode]
@@ -667,11 +667,11 @@ namespace System
{
MulticastDelegate realDelegate = Delegate.InternalAllocLike(this);
realDelegate.CtorOpened(target, methodPtr, shuffleThunk);
- this._invocationList = realDelegate;
+ _invocationList = realDelegate;
this._target = this;
this._methodPtr = callThunk;
this._methodPtrAux = creatorMethod;
- this._invocationCount = GetInvokeMethod();
+ _invocationCount = GetInvokeMethod();
}
[System.Diagnostics.DebuggerNonUserCode]
@@ -687,11 +687,11 @@ namespace System
{
MulticastDelegate realDelegate = Delegate.InternalAllocLike(this);
realDelegate.CtorVirtualDispatch(target, methodPtr, shuffleThunk);
- this._invocationList = realDelegate;
+ _invocationList = realDelegate;
this._target = this;
this._methodPtr = callThunk;
this._methodPtrAux = creatorMethod;
- this._invocationCount = GetInvokeMethod();
+ _invocationCount = GetInvokeMethod();
}
[System.Diagnostics.DebuggerNonUserCode]