public static void GetDelegateData(Delegate instance, SerializationInfo info, StreamingContext ctx) { Delegate[] invocationList = instance.GetInvocationList(); DelegateSerializationHolder.DelegateEntry delegateEntry = null; for (int i = 0; i < invocationList.Length; i++) { Delegate @delegate = invocationList[i]; string text = (@delegate.Target == null) ? null : ("target" + i); DelegateSerializationHolder.DelegateEntry delegateEntry2 = new DelegateSerializationHolder.DelegateEntry(@delegate, text); if (delegateEntry == null) { info.AddValue("Delegate", delegateEntry2); } else { delegateEntry.delegateEntry = delegateEntry2; } delegateEntry = delegateEntry2; if (@delegate.Target != null) { info.AddValue(text, @delegate.Target); } } info.SetType(typeof(DelegateSerializationHolder)); }
private DelegateSerializationHolder(SerializationInfo info, StreamingContext ctx) { DelegateSerializationHolder.DelegateEntry delegateEntry = (DelegateSerializationHolder.DelegateEntry)info.GetValue("Delegate", typeof(DelegateSerializationHolder.DelegateEntry)); int num = 0; DelegateSerializationHolder.DelegateEntry delegateEntry2 = delegateEntry; while (delegateEntry2 != null) { delegateEntry2 = delegateEntry2.delegateEntry; num++; } if (num == 1) { this._delegate = delegateEntry.DeserializeDelegate(info); } else { Delegate[] array = new Delegate[num]; delegateEntry2 = delegateEntry; for (int i = 0; i < num; i++) { array[i] = delegateEntry2.DeserializeDelegate(info); delegateEntry2 = delegateEntry2.delegateEntry; } this._delegate = Delegate.Combine(array); } }
internal static DelegateSerializationHolder.DelegateEntry GetDelegateSerializationInfo(SerializationInfo info, Type delegateType, object target, MethodInfo method, int targetIndex) { if (method == null) { throw new ArgumentNullException("method"); } if (!method.IsPublic || (method.DeclaringType != null && !method.DeclaringType.IsVisible)) { new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand(); } Type baseType = delegateType.BaseType; if (baseType == null || (baseType != typeof(Delegate) && baseType != typeof(MulticastDelegate))) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); } if (method.DeclaringType == null) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_GlobalMethodSerialization")); } DelegateSerializationHolder.DelegateEntry delegateEntry = new DelegateSerializationHolder.DelegateEntry(delegateType.FullName, delegateType.Module.Assembly.FullName, target, method.ReflectedType.Module.Assembly.FullName, method.ReflectedType.FullName, method.Name); if (info.MemberCount == 0) { info.SetType(typeof(DelegateSerializationHolder)); info.AddValue("Delegate", delegateEntry, typeof(DelegateSerializationHolder.DelegateEntry)); } if (target != null) { string text = "target" + targetIndex; info.AddValue(text, delegateEntry.target); delegateEntry.target = text; } string name = "method" + targetIndex; info.AddValue(name, method); return delegateEntry; }
public object GetRealObject(StreamingContext context) { int length1 = 0; for (DelegateSerializationHolder.DelegateEntry delegateEntry = this.m_delegateEntry; delegateEntry != null; delegateEntry = delegateEntry.Entry) { ++length1; } int num = length1 - 1; if (length1 == 1) { return((object)this.GetDelegate(this.m_delegateEntry, 0)); } object[] objArray = new object[length1]; for (DelegateSerializationHolder.DelegateEntry de = this.m_delegateEntry; de != null; de = de.Entry) { --length1; objArray[length1] = (object)this.GetDelegate(de, num - length1); } MulticastDelegate multicastDelegate = (MulticastDelegate)objArray[0]; object[] invocationList = objArray; int length2 = invocationList.Length; return((object)multicastDelegate.NewMulticastDelegate(invocationList, length2)); }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { int targetIndex = 0; Object[] invocationList = _invocationList as Object[]; if (invocationList == null) { MethodInfo method = Method; // 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")); } // We can't deal with secure delegates either. if (!InvocationListLogicallyNull() && !_invocationCount.IsNull() && !_methodPtrAux.IsNull()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } DelegateSerializationHolder.GetDelegateSerializationInfo(info, this.GetType(), Target, method, targetIndex); } else { DelegateSerializationHolder.DelegateEntry nextDe = null; int invocationCount = (int)_invocationCount; 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()) { continue; } // We can't deal with secure delegates either. if (!d.InvocationListLogicallyNull() && !d._invocationCount.IsNull() && !d._methodPtrAux.IsNull()) { continue; } 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")); } } }
private Delegate GetDelegate(DelegateSerializationHolder.DelegateEntry de, int index) { Delegate @delegate; try { if (de.methodName == null || de.methodName.Length == 0) { this.ThrowInsufficientState("MethodName"); } if (de.assembly == null || de.assembly.Length == 0) { this.ThrowInsufficientState("DelegateAssembly"); } if (de.targetTypeName == null || de.targetTypeName.Length == 0) { this.ThrowInsufficientState("TargetTypeName"); } RuntimeType type1 = (RuntimeType)Assembly.GetType_Compat(de.assembly, de.type); RuntimeType type2 = (RuntimeType)Assembly.GetType_Compat(de.targetTypeAssembly, de.targetTypeName); if (this.m_methods != null) { object firstArgument = de.target != null?RemotingServices.CheckCast(de.target, type2) : (object)null; @delegate = Delegate.CreateDelegateNoSecurityCheck(type1, firstArgument, this.m_methods[index]); } else { @delegate = de.target == null?Delegate.CreateDelegate((Type)type1, (Type)type2, de.methodName) : Delegate.CreateDelegate((Type)type1, RemotingServices.CheckCast(de.target, type2), de.methodName); } if (!(@delegate.Method != (MethodInfo)null) || @delegate.Method.IsPublic) { if (@delegate.Method.DeclaringType != (Type)null) { if (@delegate.Method.DeclaringType.IsVisible) { goto label_16; } } else { goto label_16; } } new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand(); } catch (Exception ex) { if (ex is SerializationException) { throw ex; } throw new SerializationException(ex.Message, ex); } label_16: return(@delegate); }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { int targetIndex = 0; Object[] invocationList = _invocationList as Object[]; if (invocationList == null) { MethodInfo method = Method; // if it is a delegate over a DynamicMethod or an unmanaged function pointer, throw if (method is System.Reflection.Emit.DynamicMethod || method is System.Reflection.Emit.DynamicMethod.RTDynamicMethod || IsUnmanagedFunctionPtr()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } // We can't deal with secure delegates either. if (_invocationList != null && !_invocationCount.IsNull()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } DelegateSerializationHolder.GetDelegateSerializationInfo(info, this.GetType(), Target, method, targetIndex); } else { DelegateSerializationHolder.DelegateEntry nextDe = null; int invocationCount = (int)_invocationCount; for (int i = invocationCount; --i >= 0;) { MulticastDelegate d = (MulticastDelegate)invocationList[i]; MethodInfo method = d.Method; if (method is System.Reflection.Emit.DynamicMethod || method is System.Reflection.Emit.DynamicMethod.RTDynamicMethod || IsUnmanagedFunctionPtr()) { continue; } // We can't deal with secure delegates either. if (d._invocationList != null && !d._invocationCount.IsNull()) { continue; } 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")); } } }
internal DelegateSerializationHolder.DelegateEntry GetDelegateSerializationInfo(SerializationInfo info, StreamingContext context, int targetIndex) { DelegateSerializationHolder.DelegateEntry de = DelegateSerializationHolder.GetDelegateSerializationInfo(info, this.GetType(), Target, Method, targetIndex); if (_prev != null) { DelegateSerializationHolder.DelegateEntry previousde = _prev.GetDelegateSerializationInfo(info, context, ++targetIndex); de.Entry = previousde; } return(de); }
private DelegateSerializationHolder(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } bool flag = true; try { this.m_delegateEntry = (DelegateSerializationHolder.DelegateEntry)info.GetValue("Delegate", typeof(DelegateSerializationHolder.DelegateEntry)); } catch { this.m_delegateEntry = this.OldDelegateWireFormat(info, context); flag = false; } if (!flag) { return; } DelegateSerializationHolder.DelegateEntry delegateEntry = this.m_delegateEntry; int length = 0; for (; delegateEntry != null; delegateEntry = delegateEntry.delegateEntry) { if (delegateEntry.target != null) { string name = delegateEntry.target as string; if (name != null) { delegateEntry.target = info.GetValue(name, typeof(object)); } } ++length; } MethodInfo[] methodInfoArray = new MethodInfo[length]; int index; for (index = 0; index < length; ++index) { string name = "method" + (object)index; methodInfoArray[index] = (MethodInfo)info.GetValueNoThrow(name, typeof(MethodInfo)); if (methodInfoArray[index] == (MethodInfo)null) { break; } } if (index != length) { return; } this.m_methods = methodInfoArray; }
private DelegateSerializationHolder(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } bool flag = true; try { this.m_delegateEntry = (DelegateSerializationHolder.DelegateEntry)info.GetValue("Delegate", typeof(DelegateSerializationHolder.DelegateEntry)); } catch { this.m_delegateEntry = this.OldDelegateWireFormat(info, context); flag = false; } if (flag) { DelegateSerializationHolder.DelegateEntry delegateEntry = this.m_delegateEntry; int num = 0; while (delegateEntry != null) { if (delegateEntry.target != null) { string text = delegateEntry.target as string; if (text != null) { delegateEntry.target = info.GetValue(text, typeof(object)); } } num++; delegateEntry = delegateEntry.delegateEntry; } MethodInfo[] array = new MethodInfo[num]; int i; for (i = 0; i < num; i++) { string name = "method" + i; array[i] = (MethodInfo)info.GetValueNoThrow(name, typeof(MethodInfo)); if (array[i] == null) { break; } } if (i == num) { this.m_methods = array; } } }
private Delegate GetDelegate(DelegateSerializationHolder.DelegateEntry de, int index) { Delegate @delegate; try { if (de.methodName == null || de.methodName.Length == 0) { this.ThrowInsufficientState("MethodName"); } if (de.assembly == null || de.assembly.Length == 0) { this.ThrowInsufficientState("DelegateAssembly"); } if (de.targetTypeName == null || de.targetTypeName.Length == 0) { this.ThrowInsufficientState("TargetTypeName"); } RuntimeType type = (RuntimeType)Assembly.GetType_Compat(de.assembly, de.type); RuntimeType runtimeType = (RuntimeType)Assembly.GetType_Compat(de.targetTypeAssembly, de.targetTypeName); if (this.m_methods != null) { object firstArgument = (de.target != null) ? RemotingServices.CheckCast(de.target, runtimeType) : null; @delegate = Delegate.CreateDelegateNoSecurityCheck(type, firstArgument, this.m_methods[index]); } else if (de.target != null) { @delegate = Delegate.CreateDelegate(type, RemotingServices.CheckCast(de.target, runtimeType), de.methodName); } else { @delegate = Delegate.CreateDelegate(type, runtimeType, de.methodName); } if ((@delegate.Method != null && [email protected]) || (@delegate.Method.DeclaringType != null && [email protected])) { new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand(); } } catch (Exception ex) { if (ex is SerializationException) { throw ex; } throw new SerializationException(ex.Message, ex); } return(@delegate); }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { int targetIndex = 0; object[] array = this._invocationList as object[]; if (array == null) { MethodInfo method = base.Method; if (!(method is RuntimeMethodInfo) || this.IsUnmanagedFunctionPtr()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } if (!this.InvocationListLogicallyNull() && !this._invocationCount.IsNull() && !this._methodPtrAux.IsNull()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } DelegateSerializationHolder.GetDelegateSerializationInfo(info, base.GetType(), base.Target, method, targetIndex); return; } else { DelegateSerializationHolder.DelegateEntry delegateEntry = null; int num = (int)this._invocationCount; int num2 = num; while (--num2 >= 0) { MulticastDelegate multicastDelegate = (MulticastDelegate)array[num2]; MethodInfo method2 = multicastDelegate.Method; if (method2 is RuntimeMethodInfo && !this.IsUnmanagedFunctionPtr() && (multicastDelegate.InvocationListLogicallyNull() || multicastDelegate._invocationCount.IsNull() || multicastDelegate._methodPtrAux.IsNull())) { DelegateSerializationHolder.DelegateEntry delegateSerializationInfo = DelegateSerializationHolder.GetDelegateSerializationInfo(info, multicastDelegate.GetType(), multicastDelegate.Target, method2, targetIndex++); if (delegateEntry != null) { delegateEntry.Entry = delegateSerializationInfo; } delegateEntry = delegateSerializationInfo; } } if (delegateEntry == null) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } return; } }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { int targetIndex = 0; object[] objArray = this._invocationList as object[]; if (objArray == null) { MethodInfo method = base.Method; if (((method is DynamicMethod) || (method is DynamicMethod.RTDynamicMethod)) || this.IsUnmanagedFunctionPtr()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } if ((this._invocationList != null) && !this._invocationCount.IsNull()) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } DelegateSerializationHolder.GetDelegateSerializationInfo(info, base.GetType(), base.Target, method, targetIndex); } else { DelegateSerializationHolder.DelegateEntry entry = null; int index = (int)this._invocationCount; while (--index >= 0) { MulticastDelegate delegate2 = (MulticastDelegate)objArray[index]; MethodInfo info3 = delegate2.Method; if (((!(info3 is DynamicMethod) && !(info3 is DynamicMethod.RTDynamicMethod)) && !this.IsUnmanagedFunctionPtr()) && ((delegate2._invocationList == null) || delegate2._invocationCount.IsNull())) { DelegateSerializationHolder.DelegateEntry entry2 = DelegateSerializationHolder.GetDelegateSerializationInfo(info, delegate2.GetType(), delegate2.Target, info3, targetIndex++); if (entry != null) { entry.Entry = entry2; } entry = entry2; } } if (entry == null) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidDelegateType")); } } }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); Delegate[] invocationList = m_helperObject as Delegate[]; if (invocationList == null) { if (Method == null) { throw new SerializationException(SR.DelegateSer_InsufficientMetadata); } DelegateSerializationHolder.GetDelegateSerializationInfo(info, this.GetType(), Target, Method, 0); } else { int targetIndex = 0; DelegateSerializationHolder.DelegateEntry previousEntry = null; int invocationCount = (int)m_extraFunctionPointerOrData; for (int i = invocationCount; --i >= 0;) { MulticastDelegate d = (MulticastDelegate)invocationList[i]; if (d.Method == null) { throw new SerializationException(SR.DelegateSer_InsufficientMetadata); } DelegateSerializationHolder.DelegateEntry de = DelegateSerializationHolder.GetDelegateSerializationInfo(info, d.GetType(), d.Target, d.Method, targetIndex++); if (previousEntry != null) { previousEntry.NextEntry = de; } previousEntry = de; } } }
public object GetRealObject(StreamingContext context) { int num = 0; for (DelegateSerializationHolder.DelegateEntry delegateEntry = this.m_delegateEntry; delegateEntry != null; delegateEntry = delegateEntry.Entry) { num++; } int num2 = num - 1; if (num == 1) { return(this.GetDelegate(this.m_delegateEntry, 0)); } object[] array = new object[num]; for (DelegateSerializationHolder.DelegateEntry delegateEntry2 = this.m_delegateEntry; delegateEntry2 != null; delegateEntry2 = delegateEntry2.Entry) { num--; array[num] = this.GetDelegate(delegateEntry2, num2 - num); } return(((MulticastDelegate)array[0]).NewMulticastDelegate(array, array.Length)); }
internal static DelegateSerializationHolder.DelegateEntry GetDelegateSerializationInfo(SerializationInfo info, Type delegateType, object target, MethodInfo method, int targetIndex) { if (method == (MethodInfo)null) { throw new ArgumentNullException("method"); } if (!method.IsPublic || method.DeclaringType != (Type)null && !method.DeclaringType.IsVisible) { new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand(); } Type baseType = delegateType.BaseType; if (baseType == (Type)null || baseType != typeof(Delegate) && baseType != typeof(MulticastDelegate)) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); } if (method.DeclaringType == (Type)null) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_GlobalMethodSerialization")); } DelegateSerializationHolder.DelegateEntry delegateEntry = new DelegateSerializationHolder.DelegateEntry(delegateType.FullName, delegateType.Module.Assembly.FullName, target, method.ReflectedType.Module.Assembly.FullName, method.ReflectedType.FullName, method.Name); if (info.MemberCount == 0) { info.SetType(typeof(DelegateSerializationHolder)); info.AddValue("Delegate", (object)delegateEntry, typeof(DelegateSerializationHolder.DelegateEntry)); } if (target != null) { string name = "target" + (object)targetIndex; info.AddValue(name, delegateEntry.target); delegateEntry.target = (object)name; } string name1 = "method" + (object)targetIndex; info.AddValue(name1, (object)method); return(delegateEntry); }
/// <include file='doc\MulticastDelegate.uex' path='docs/doc[@for="MulticastDelegate.GetObjectData"]/*' /> public override void GetObjectData(SerializationInfo info, StreamingContext context) { int targetIndex = 0; DelegateSerializationHolder.DelegateEntry de = GetDelegateSerializationInfo(info, context, targetIndex); }