How to pass a Type to a method for a return of the same type
Struggling to find the right syntax for this. I'm trying to specify a type that should be used to create a new instance and then return it. Example code (doesn't compile):
private T SingleDataObjectFromXDoc<T>(XDocument xDoc, string elementName) { XElement SingleElement = xDoc.Descendants(elementName).First(); return new (T)(SingleElement); }
private T SingleDataObjectFromXDoc<T>(XDocument xDoc, string elementName) { XElement SingleElement = xDoc.Descendants(elementName).First(); return new (T)(SingleElement); }
In this instance, the constructors of each Type I'll be passing will receive the XElement and subsequently update its properties from the XElement.