how to join a set of XElements to the values of a struct?
Posted
by jcollum
on Stack Overflow
See other posts from Stack Overflow
or by jcollum
Published on 2010-04-13T22:31:47Z
Indexed on
2010/04/13
22:32 UTC
Read the original article
Hit count: 329
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?
© Stack Overflow or respective owner