Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么System.Delegate实现ISerializable?_C#_Delegates_Iserializable - Fatal编程技术网

C# 为什么System.Delegate实现ISerializable?

C# 为什么System.Delegate实现ISerializable?,c#,delegates,iserializable,C#,Delegates,Iserializable,如果查看System.Delegate的源代码,您将看到它实现了ISerializable接口: [Serializable, ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual),__DynamicallyInvokable] public abstract class Delegate : ICloneable, ISerializable 但实际实现引发了一个异常: public virtual void GetObj

如果查看
System.Delegate
的源代码,您将看到它实现了
ISerializable
接口:

[Serializable, ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual),__DynamicallyInvokable]
public abstract class Delegate : ICloneable, ISerializable
但实际实现引发了一个异常:

public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
    throw new NotSupportedException();
}

为什么要使用
ISerializable
;是否有任何实际使用序列化的派生类型?

二进制序列化要求被序列化的类的基类也是可序列化的。但您从未实际序列化Delegate类型的对象,它是一个抽象类。您将序列化一个多播委托。其中包含GetObjectData()的实现。了解
MulticaseDelegate
。你是说你可以二进制序列化一个委托(multicasedelegate)?试试看。这也是找出为什么这是一个你不应该(几乎)使用的功能的最好方法。