De serializing a list of strings without creating a new class?

I have an XML configuration file with a set of lines like this:

<SomeSetting>value</SomeSetting>
<SomeOtherSetting>value</SomeOtherSetting>
<TypesOfThings>
  <Thing>Type 1</Thing>
  <Thing>Type 2</Thing>
  <Thing>Type 3</Thing>
</TypesOfThings>

These "things" become parameters in the user interface of the application.

My question is, should I create an item class to use Serialization correctly, or is there a way to use attributes to read strings right in the list?

For example (bodies and private vars are removed for brevity, this is .NET 2.0):

[Serializable]
public class Config
{
   public string SomeSetting
   { 
        get;
        set;
   }


   public string SomeOtherSetting
   { 
        get;
        set;
   }

   public List<string> TypesOfThings
   {
      get;
      set;
   }
}
+3
source share
1 answer

You specify how to serialize it using XmlArrayAttribute :

[XmlArray(ElementName = "TypesOfThings")]
[XmlArrayItem(ElementName="Thing")]
public List<string> TypesOfThings
{
   get;
   set;
}

Edit: element name is the relevance specified with XmlArrayItemAttribute

+7
source

All Articles