我有幾個Delphi Prism類,具有索引屬性,我在C#web應用程序中使用了很多(我們正在將一個大的Delphi Win32系統遷移到ASP.Net )。我的問題是,似乎C#不能看到索引屬性,如果他們不是他們的類的默認屬性。也許我做錯了什麼,但我完全失去了。如何使Delphi Prism索引屬性對C#可見,當屬性不是默認的時
我知道這個問題看起來很像一個錯誤報告,但我需要知道是否有人知道如何解決這個問題之前我報告一個錯誤。
如果我有一類這樣的:
TMyClass = public class
private
...
method get_IndexedBool(index: Integer): boolean;
method set_IndexedBool(index: Integer; value: boolean);
public
property IndexedBool[index: Integer]: boolean
read get_IndexedBool
write set_IndexedBool; default; // make IndexedBool the default property
end;
我可以使用這個類在C#這樣的:
var myObj = new TMyClass();
myObj[0] = true;
但是,如果TMyClass這樣定義:
TMyClass = public class
private
...
method get_IndexedBool(index: Integer): boolean;
method set_IndexedBool(index: Integer; value: boolean);
public
property IndexedBool[index: Integer]: boolean
read get_IndexedBool
write set_IndexedBool; // IndexedBool is not the default property anymore
end;
然後IndexedBool屬性在C#中變得不可見。我可以用它的唯一辦法是這樣做的:
var myObj = new TMyClass();
myObj.set_IndexedBool(0, true);
我不知道如果我失去了一些東西,但我不能看到IndexedBool財產,如果我刪除默認在財產申報。除此之外,我敢肯定,直接訪問類實例的私有方法是錯誤的。
任何想法?
是的,我用它來實現在我的應用程序上使用的一些C#類的索引屬性,但問題是我的Delphi Prism類。我認爲這是一個Delphi Prism限制,但是因爲它在VB上工作,所以我認爲C#是應該指責的。 – Arcturus 2010-03-19 11:49:19
是的,這是C#的限制,而不是Delphi Prism的限制。你不得不繞過C#支持而不是Prism支持。 – jamiei 2010-03-19 12:20:08
更新了我的回答以反映。 – jamiei 2010-03-20 11:26:56