[英]How can I determine the class of an XML serialized object in C# before I deserialize it?
[英]How to ensure that object can be serialized to xml
我有這種方法來確保對象可以序列化為二進制文件:
public static bool IsSerializable<T>(this T obj)
{
return typeof (T).Attributes.HasFlag(TypeAttributes.Serializable) || obj is ISerializable;
}
但是我不能為XML做同樣的事情。 例如,我可以這樣寫
public static bool IsXmlSerializable<T>()
{
var type = typeof (T);
return type.GetInterface("IXmlSerializable") != null;
}
但是如何檢查XmlType屬性或其他內容?
請指教。
下面是一些代碼,顯示了如何使用isSerializable屬性: http : //msdn.microsoft.com/zh-cn/library/system.type.isserializable( v=vs.110) .aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.