I have an enum width descriptions:
public enum PostTypes {
[Description("Business")]
Business = 1 << 0,
[Description("Design"]
Design = 1 << 1,
[Description("Marketing")]
Marketing = 1 << 2,
} // PostTypes
I would like to get an Enum based on Description, so:
1 - If I have String="Business" I would get PostTypes.Business.
2 - If I have String[] = new String[] { "Business", "Design" } I would have PostTypes.Business | PostTypes.Design.
UPDATE
I am using the following:
Enum.GetValues(typeof(PostTypes)).Cast<PostTypes>().Where(v => new String[] { "Business", "Design" }.Contains(v.GetDescription())).Aggregate((a, b) => a | b);
This is working even for Flag enums and string arrays.
Could someone, please, help me in creating an extension where I pass the enum type and use a func for setting the rule for search, either the Description attribute or any other.
How can I do this?
Thank You, Miguel