Suppose I have XML. For instance:
<User>
<Name>X</Name>
<Gender>Y</Gender>
<ImageUrl>Z</ImageUrl>
</User>
and I have a class called User.
public class User
{
public User(string name, string gender, string imageUrl)
{
Name = name;
Gender = gender;
ImageUrl = imageUrl;
}
public string Name { get; }
public string Gender { get; }
public string ImageUrl { get; }
}
which only accepts the constructor public User(string name, string gender, string ImageUrl)and does not allow setting for properties, what is the best way to parse this xml in these objects using linq and C #?
In a rough manner, you can create anonymous objects, and then iterate over them to create the necessary objects. Is there a more efficient way to do this?
source
share