1

I have the following enum type defined:

public enum Level
{

    [XmlEnum("1")] ReadLevel = 1,
    [XmlEnum("2")] WriteLevel = 2, 

}

I also have a list defined which has the type of this enum

public List<Level> MyList

I want to store the list as a comma seperated string with the numbers and read it back and use the enum levels in conditional statements.

The set method I have defined, but how do I markup the get method? Currently

 get
 {
    return string.Join(",", MyList);
 }

returns me the text of the enum (like ReadLevel, WriteLevel)

5
  • Can you be a little more specific about why you want to do this? It would seem much better to serialize it as a list if you can Commented Mar 10, 2018 at 9:48
  • @AluanHaddad You have an example of what you mean? Commented Mar 10, 2018 at 10:12
  • no I'm asking why you're doing this at all? Commented Mar 10, 2018 at 10:13
  • @AluanHaddad Well I'm learning serialization. Commented Mar 10, 2018 at 10:17
  • if you're serializing to XML you can represent the list as a set of child elements Commented Mar 10, 2018 at 10:19

1 Answer 1

1

Try casting your enum objects to int

get { return string.Join(",", MyList.Select(x => (int)x)); }
Sign up to request clarification or add additional context in comments.

3 Comments

You don't need ToList - avoid superstitious code.
Thanks Aluan, I said in the comment that the toList may be not needed
Thanks. Works without the ToList

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.