Say you have a group of objects you're creating to handle some XML parsing and all of them take the exact same object, XElement ... as such
public class User
{
public User(XElement xmlElement)
{
Id = xmlElement.GetElementValue("UserId");
}
public string Id { get; set; }
}
What I would like to do is a method kinda like this ..
public static T ToParsedObject<T>(this XElement xmlElement) where T : new()
{
return new T(xmlElement);
}
I don't think it's possible to do a static (extension method) like this, but I would like to make this a single method I can re-use. I'm tired of writing ones like ...
public static User ToUser(this XElement xmlElement)
{
return new User(xmlElement);
}
Any ideas or guidance?