5

I searched the web and found how to add specific custom data type in settings. I'm inserting data by my self, not by code while program running. My problem was how to add custom data type to combobox in designer. Now I figured it out and need advice, how to add data type array of this type. I'll show on simple example.

I have this class

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

in settings.setting i have setting ProductSettings, type MyApp.Data.Product, scope Application and default value contains following

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

By this way it works just fine. But now, I need get a collection of Products from settings file, so I tryed to specify type as MyApp.Data.Product[] but it can't be. Designer pop-up window and says "MyApp.Data.Product[] is not defined.". How can I figure it out?

Thanks

PF: this project is just class library used from WPF application - if matters

skaffman
  • 398,947
  • 96
  • 818
  • 769
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93

1 Answers1

1

Use System.Collections.Generic.List<MyApp.Data.Product>. Or you can create a class that inherites from List<MyApp.Data.Product>

Then in the value, you will have this format:

<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>
LostInComputer
  • 15,188
  • 4
  • 41
  • 49
  • Thanks for advice, but VS still gives me error message **Type: System.Collections.Generic.List is not defined.** – Ondrej Janacek Sep 04 '11 at 09:03
  • I don't know what's wrong. Here is my sample showing how I did it: http://dl.dropbox.com/u/14576915/CollectionInSettings.zip – LostInComputer Sep 04 '11 at 23:45
  • Really nice sample, I appreciate it, but it gives me NullPointerException in ShowProduct method :( Fortunately your second solution solved my problem (class derived from List). This settings editor in VS is really stupid, it even did not add xml tags for me so I have to copy them by my self. Add one more answer to this question (answer with the working solution for me) and I will mark it as good answer -> you will gain points and users will find working solution for this problem ;-) Thanks once more. – Ondrej Janacek Sep 05 '11 at 18:38