2

I have an enumeration with [Flag] attribute set on it.

[Flags]
public enum PageTags { IsBlog = 2, HasAnalytics = 4, AppearsInSitemap = 8 }

Now, from an XML file, I get a string representation of the page metadata:

<page ... tags="IsBlog, HasAnalytics" />

My question is, how can I convert that CSV string into a variable of type PageTags?

PageTags tags = XElement.Attribute("tags").Value.?;

1 Answer 1

3

Check this Enum.Parse overload:

Sign up to request clarification or add additional context in comments.

1 Comment

The point is, Enum.Parse method also accepts a CSV string. That's cool.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.