簡體   English   中英

自定義數據類型在Settings.settings中作為類的數組

[英]Custom data type in Settings.settings as array of class

我在網上搜索並找到了如何在設置中添加特定的自定義數據類型。 我正在自己插入數據,而不是在程序運行時通過代碼插入數據。 我的問題是如何在設計器中向組合框添加自定義數據類型。 現在我想出來並需要建議,如何添加這種類型的數據類型數組。 我將以簡單的例子展示。

我有這門課

[Serializable()]
public class Product
{
public string Name { get; set; }
public int Price { get; set; }
}

在settings.setting中我設置了ProductSettings ,輸入MyApp.Data.Product ,scope 應用程序和默認值包含以下內容

<xml definition>
<Product xlmns:xsi=.....>
<Name>Banana</Name>
<Price>1</Price>
</Product>

通過這種方式它工作得很好。 但是現在,我需要從設置文件中獲取一組產品,所以我嘗試將類型指定為MyApp.Data.Product [],但它不能。 設計器彈出窗口並顯示“ MyApp.Data.Product []未定義。 我怎么能搞清楚?

謝謝

PF:這個項目只是WPF應用程序中使用的類庫 - 如果重要的話

使用System.Collections.Generic.List <MyApp.Data.Product>。 或者,您可以創建一個繼承自List <MyApp.Data.Product>的類

然后在值中,您將具有以下格式:

<ArrayOfProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=
"http://www.w3.org/2001/XMLSchema">
  <Product>
    <Name>Banana</Name>
    <Price>1</Price>
  </Product>
</ArrayOfProduct>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM