With generic-types, it's possible to give a dynamic type, but is it possible to also give a dynamic value ?
For example, I receive an XML response from a Rest API and I want to Deserialize it into an object:
<tsResponse>
<value id="hello"/>
</tsResponse>
[XmlRoot("tsResponse")]
public class TsResponse<T, string myNodeName>
{
[XmlElement(myNodeName)]
public T Object { get; set; }
}
public class User
{
[XmlAttribute("id")]
public string Id { get; set; }
}
To make it works I need to call something like this:
using (StringReader sr = new StringReader(xml))
{
XmlSerializer serializer = new XmlSerializer(typeof(TsResponse<User>));
TsResponse<User, "value"> responseXml = (TsResponse<User, "value">)serializer.Deserialize(sr);
}
Is it possible to do something like this ?
public class A<T>XmlElement- as attributes in general - only work with compile-time literals, so you cannot provide a dynamic value to them.static interfacemembers... depending on if it supportsconstmembers of interface types, then you could pass that toXmlElement( here ). Hmmm.... UPDATE: Nevermind, onlystatic abstractmembers can, notconstmembers.