I have the code that works:
XML:
<parameters>
<company>asur_nsi</company>
<password>lapshovva</password>
<user>dogm_LapshovVA</user>
</parameters>
Code:
XElement documentRoot = XElement.Load(webConfigFilePath);
var param = from p in documentRoot.Descendants("parameters")
select new
{
company = p.Element("company").Value,
password = p.Element("password").Value,
user = p.Element("user").Value
};
foreach (var p in param)
{
AuthContext ac = new AuthContext()
{
Company = p.company,
Password = p.password,
User = p.user
};
}
But, I’d like to make it better and shorter and want to return the object of AuthContext type immediately. I want to move creation of AuthContext object to “select new” section in some way.
1 Answer