how to join a set of XElements to the values of a struct?
- by jcollum
Let's say I have a struct that contains local environments:
public struct Environments
{
public const string Dev = "DEV";
public const string Qa1 = "SQA";
public const string Prod1 = "PROD";
public const string Prod2 = "PROD_SA";
public const string Uat = "UAT";
}
And I'd like to pull a set of XElements out of an xml doc, but only those elements that have a key that matches a value in a struct.
this.environments =(from e in
settings.Element("Settings").Element("Environments")
.Elements("Environment")
.Where( x => x.HasAttribute("name") )
join f in [struct?] on e.Attribute("name")
equals [struct value?]).ToDictionary(...)
How would I go about doing this? Do I need reflection to get the values of the constants in the struct?