public class MyDataTable : DataTable
{
public string MyProperty { get; set; }
public DataTable MyData { get; set; }
public void MyMethod()
{
//...do some processing on itself
MyData = this;
}
}
我創建了這個繼承DataTable的MyDataTable類。關於繼承DataTable的問題
public class MyClass
{
public void ProcessData()
{
MyDataTable table = new MyDataTable();
table.MyMethod();
AcceptDataTable(table); //it won't accept the table parameter.
AcceptDataTable(table.MyData); //it still won't accept the table parameter.
AcceptDataTable((DataTable)table); //it still won't accept the table parameter.
}
public void AcceptDataTable(DataTable table)
{
Service1.SubmitData(table); //actually this is where it fails. It is a WCF Service's method that takes a DataTable as parameter. It works fine if I pass a DataTable, but not MyDataTable
//There was an error while trying to serialize parameter http://tempuri.org/:dt. The InnerException message was 'Type 'SubmitData' with data contract name MyDataTable
}
}
列表中的錯誤消息。這應該工作。 –
我編輯過你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –
我只是試過了,沒有錯誤 –