private Delegate GetDelegate(DelegateEntry de, int index) { Delegate d; try { if (de.methodName == null || de.methodName.Length == 0) { ThrowInsufficientState("MethodName"); } if (de.assembly == null || de.assembly.Length == 0) { ThrowInsufficientState("DelegateAssembly"); } if (de.targetTypeName == null || de.targetTypeName.Length == 0) { ThrowInsufficientState("TargetTypeName"); } // We cannot use Type.GetType directly, because of AppCompat - assembly names starting with '[' would fail to load. RuntimeType type = (RuntimeType)Assembly.GetType_Compat(de.assembly, de.type); RuntimeType targetType = (RuntimeType)Assembly.GetType_Compat(de.targetTypeAssembly, de.targetTypeName); // If we received the new style delegate encoding we already have the target MethodInfo in hand. if (m_methods != null) { #if FEATURE_REMOTING Object target = de.target != null?RemotingServices.CheckCast(de.target, targetType) : null; #else if (!targetType.IsInstanceOfType(de.target)) { throw new InvalidCastException(); } Object target = de.target; #endif d = Delegate.CreateDelegateNoSecurityCheck(type, target, m_methods[index]); } else { if (de.target != null) #if FEATURE_REMOTING { d = Delegate.CreateDelegate(type, RemotingServices.CheckCast(de.target, targetType), de.methodName); } #else { if (!targetType.IsInstanceOfType(de.target)) { throw new InvalidCastException(); } d = Delegate.CreateDelegate(type, de.target, de.methodName); } #endif else { d = Delegate.CreateDelegate(type, targetType, de.methodName); } }
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); }
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); }
private Delegate GetDelegate(DelegateEntry de, int index) { Delegate d; try { if (de.methodName == null || de.methodName.Length == 0) { ThrowInsufficientState("MethodName"); } if (de.assembly == null || de.assembly.Length == 0) { ThrowInsufficientState("DelegateAssembly"); } if (de.targetTypeName == null || de.targetTypeName.Length == 0) { ThrowInsufficientState("TargetTypeName"); } // We cannot use Type.GetType directly, because of AppCompat - assembly names starting with '[' would fail to load. RuntimeType type = (RuntimeType)Assembly.GetType_Compat(de.assembly, de.type); // {de.targetTypeAssembly, de.targetTypeName} do not actually refer to the type of the target, but the reflected // type of the method. Those types may be the same when the method is on the target's type or on a type in its // inheritance chain, but those types may not be the same when the method is an extension method for the // target's type or a type in its inheritance chain. // If we received the new style delegate encoding we already have the target MethodInfo in hand. if (m_methods != null) { // The method info is serialized, so the target type info is redundant. The desktop framework does no // additional verification on the target type info. d = Delegate.CreateDelegateNoSecurityCheck(type, de.target, m_methods[index]); } else { if (de.target != null) { // For consistency with the desktop framework, when the method info is not serialized for a closed // delegate, the method is assumed to be on the target's type or in its inheritance chain. An extension // method would not work on this path for the above reason and also because the delegate binds to // instance methods only. The desktop framework does no additional verification on the target type info. d = Delegate.CreateDelegate(type, de.target, de.methodName); } else { RuntimeType targetType = (RuntimeType)Assembly.GetType_Compat(de.targetTypeAssembly, de.targetTypeName); d = Delegate.CreateDelegate(type, targetType, de.methodName); } } } catch (Exception e) { if (e is SerializationException) { throw e; } throw new SerializationException(e.Message, e); } return(d); }
private Delegate GetDelegate(DelegateEntry de, int index) { Delegate d; try { if (de.methodName == null || de.methodName.Length == 0) { ThrowInsufficientState("MethodName"); } if (de.assembly == null || de.assembly.Length == 0) { ThrowInsufficientState("DelegateAssembly"); } if (de.targetTypeName == null || de.targetTypeName.Length == 0) { ThrowInsufficientState("TargetTypeName"); } // We cannot use Type.GetType directly, because of AppCompat - assembly names starting with '[' would fail to load. RuntimeType type = (RuntimeType)Assembly.GetType_Compat(de.assembly, de.type); RuntimeType targetType = (RuntimeType)Assembly.GetType_Compat(de.targetTypeAssembly, de.targetTypeName); // If we received the new style delegate encoding we already have the target MethodInfo in hand. if (m_methods != null) { if (de.target != null && !targetType.IsInstanceOfType(de.target)) { throw new InvalidCastException(); } Object target = de.target; d = Delegate.CreateDelegateNoSecurityCheck(type, target, m_methods[index]); } else { if (de.target != null) { if (!targetType.IsInstanceOfType(de.target)) { throw new InvalidCastException(); } d = Delegate.CreateDelegate(type, de.target, de.methodName); } else { d = Delegate.CreateDelegate(type, targetType, de.methodName); } } if ((d.Method != null && !d.Method.IsPublic) || (d.Method.DeclaringType != null && !d.Method.DeclaringType.IsVisible)) { new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand(); } } catch (Exception e) { if (e is SerializationException) { throw e; } throw new SerializationException(e.Message, e); } return(d); }