爲了創建應該在ASP.NET中使用的自定義數據源,我創建了一個自定義數據源類,一個自定義編輯器和一個自定義可序列化的類。爲什麼不是我的設計器屬性在ASPX中序列化
我不明白爲什麼它不起作用......儘管我可能比所需要的屬性更多(我一直在瀏覽並嘗試幾個小時),但從我所瞭解的PersistenceMode(PersistenceMode.InnerProperty)
應該做的訣竅......另外,在我看來,我的代碼與Why can't I declare sub-elements (properties) of a UserControl in a WebForm?類似。
代碼的工作原理如下:
[ParseChildren(true)]
[PersistChildren(true)]
public class MyDataSource : DataSourceControl
{
// [much more irrelevant code...]
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(Editors.ResultRequestEditor), typeof(System.Drawing.Design.UITypeEditor))]
public ResultRequest Request { get; set; }
}
[Serializable]
[PersistChildren(true)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[ParseChildren(true)]
public class ResultRequest
{
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public string ColumnName { get; set; }
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public Type ColumnType { get; set; }
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Always)]
public object[] ResultTypeParameters { get; set; }
}
的自定義編輯似乎工作:使用後,在VS的屬性正確更新。
但是,更新的東西之後的信息沒有在ASPX文件堅持:
<cc1:MyDataSource ID="SearchDataSource1" runat="server" ProviderID="MyProvider1" />
我預料到的數據源中的一些序列,如:
<cc1:MyDataSource ID="SearchDataSource1" runat="server" ProviderID="MyProvider1">
<Request>
// blah
</Request>
</cc1:MyDataSource>
能有人請解釋爲什麼這不起作用?
您是否嘗試過沒有一些屬性,例如TypeConverters? –
我不明白你在做什麼。基本上你的意思是說:我有三個班,他們不工作。你想做什麼?你的行爲和你的期望行爲是什麼?你期望在數據源中有一些序列化?在課堂上序列化?通常序列化發生在文本或二進制文件中。所以我的下一個問題是:什麼文件? –
那麼基本上,我試圖爲'ResultRequest'類定製一個編輯器。數據源本身起作用,我不能從ASPX而不是後面的代碼中配置它。 TypeConverters在那裏,因爲默認序列化(對你的ASPX XML)不起作用 - f.ex.雖然我知道如何序列化'object []',但設計者沒有,所以我打算告訴他這是如何完成的。這也是編輯的目的。是的,我試圖添加和刪除屬性幾個小時,試圖瞭解它是如何工作的(結論:它不工作,我不明白它)。 – atlaste