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");
Type type = Assembly.Load(de.assembly).GetType(de.type, true, false);
Type targetType = Assembly.Load(de.targetTypeAssembly).GetType(de.targetTypeName, true, false);
// If we received the new style delegate encoding we already have the target MethodInfo in hand.
if (m_methods != null)
{
Object target = de.target != null ? RemotingServices.CheckCast(de.target, targetType) : null;
d = Delegate.InternalCreateDelegate(type, target, m_methods[index]);
}
else
{
if (de.target != null)
d = Delegate.CreateDelegate(type, RemotingServices.CheckCast(de.target, targetType), 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);
}
catch
{
throw new SerializationException();
}
return d;
}
#endregion