Does the spec of C# prevent calling a method from within an object's (or struct's) initializer construct?
The reason I'm asking is because I was trying to use a LINQ-to-XML statement to use gater data within the initializer. This does not work. However, if I get the data before hand saved into a local variable it works without issue. I just was wondering why this happens, since I have already figured out the error in my code.
Does Not Work:
SavedData sData = new SavedData()
{
exportLocation = data.Root.Descendants("ExportLocation").FirstOrDefault().Value,
exportType = (ExportType)data.Root.Descendants("ExportType").FirstOrDefault().Value
};
Works:
var exLoc = data.Root.Descendants("ExportLocation").FirstOrDefault().Value;
ExportType type = (ExportType)data.Root.Descendants("ExportType").FirstOrDefault().Value;
Saved Data sData = new SavedData()
{
exportLocation = exLoc,
exportType = type
};