In WCF, primitives type are serialzable, and some commonly used types are also serialzable, but some types are not serialzable , and when this types to be used in wcf as the data contract for message, then you might get into trouble.
there are ways to determine if a type is serializable or an instance is serializable. To check if a type (on the type object itself)
typeof(T).IsSerializable
or you can check on the instance
private static bool IsSerializable(T obj)
{
return ((obj is ISerializable) || (Attribute.IsDefined(typeof (T), typeof (SerializableAttribute))));
}
But be caereful that IsSerializable does not take into account the all types in the graph of objects being serialized for the serialable attribute.
You might want to check on that the reference page - how to check if an object is serializable in C#
References:
本文详细介绍了在WCF中如何判断类型及其实例是否可序列化,包括使用Type.IsSerializable方法和自定义检查函数。同时提醒注意序列化属性在对象图中的应用范围限制。

被折叠的 条评论
为什么被折叠?



