我在兩個類中做了完全相同的事情,在一個編譯器允許它很好,但另一個給我一個錯誤。爲什麼是雙重標準?有使用同樣的模式15類,但只有一個拒絕編譯,說了以下錯誤:C#雙重標準?
'AWWAInvoicingXML.AwwaTransmissionInfo' does not implement interface member 'AWWAInvoicingXML.IXmlSerializable.fromXML(System.Xml.XmlDocumentFragment)'. 'AWWAInvoicingXML.AwwaTransmissionInfo.fromXML(System.Xml.XmlDocumentFragment)' is either static, not public, or has the wrong return type.
這裏是我的源代碼,如果我註釋掉AwwaTransmissionInfo類,文件的剩餘部分只是編譯好,所以我知道這不是編譯器在第一個錯誤之後死亡的那個。我知道,我知道,這裏有內置的東西,我想在這裏做什麼,但只是假設我真的知道我在做什麼,並跳過內置序列化器出於某種原因:)
public interface IXmlSerializable {
//if this interface is implemented, the object can be serialized to XML
string toXML();
IXmlSerializable fromXML(XmlDocumentFragment inXml);
}
public class AwwaTransmissionInfo : IXmlSerializable {
public DateTime DateTime = DateTime.Now;
public int ItemCount;
public string toXML() {
throw new Exception("The method or operation is not implemented.");
}
public AwwaTransmissionInfo fromXML(XmlDocumentFragment inXml) {
throw new Exception("The method or operation is not implemented.");
}
}
public class CEmail {
public string Email = "";
public string toXML() {
throw new System.Exception("The method or operation is not implemented.");
}
public CEmail fromXML(XmlDocumentFragment inXml) {
throw new System.Exception("The method or operation is not implemented.");
}
}
CEmail未標記爲實施IXmlSerializable。那是故意的嗎? – Rob 2009-01-29 22:55:05
Bang你明白了...... OMG我盯着這很久沒有意識到這一點!作爲回答發佈,所以我可以給你的觀點:) – Jasmine 2009-01-29 22:56:53
沒有看到森林樹木的經典案例。 =) – 2009-01-29 23:03:57