Is it possible to create a generic method of type T where T has a specific attribute?
E.g.:
public static XmlDocument SerializeObjectToXml<T>(T obj)
{
//...
}
and I want to serialize only a classes with a Serializable and/or DataContract attribute:
[Serializable]
[DataContract(Name = "viewModel", Namespace = "ns")]
internal class ViewModel
{
//...
}
I’m afraid no. There are 3 types of constraints: derivation, constructor and reference/value-type.
I believe, you should check for attributes in the method body and if the serializable object doesn’t meet the criteria call a different method to process it.