Type.IsGenericParameter屬性爲false
當某個類的IsGenericParameter屬性爲false時,是表示該類爲非泛型類或方法。
此時,如果該類的變量中或者方法的參數,包含泛型變量,則會產生該錯誤。
public class XXXX : MsgParent, IMsg
{
public XXXX()
{
this.MessageType = "XXXX";
}
/// <summary>
/// 確認隊列
/// </summary>
public Queue<int> queue = new Queue<int>();
/// <summary>
///
/// </summary>
public int AlarmID = 0;
public string Serialize()
{
string strSource = "";
try
{
XmlSerializer s = new XmlSerializer(typeof(XXXXX));
Stream stream = new MemoryStream();
s.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
strSource = reader.ReadToEnd();
}
}
catch { }
return strSource;
}
public static XXXXX Deserialize(string xmlSource)
{
XXXXX obj = new XXXXX();
try
{
XmlSerializer x = new XmlSerializer(typeof(XXXXX));
Stream stream = ProtocolHelper.GetStream(xmlSource);
stream.Seek(0, SeekOrigin.Begin);
obj = (XXXXX)x.Deserialize(stream);
stream.Close();
}
catch
{ }
return obj;
}
}
}
例如這樣,就可能產生XML序列化出錯。如果把Queue去掉的話,該問題又解決了。
但是這樣又多出了許多麻煩。想要用到數據結構存儲的話,就難免出現這樣。如果是自己寫一個數據結構(不用泛型),我想應該是可以的吧。
http://msdn.microsoft.com/zh-cn/library/system.type.isgenericparameter.aspx
MSDN上的參考資料。