I am trying to write a class that will be responsible for persisting application variations. Since the parameters must be saved, the values that I submit must be serialized.
Initially, I thought I could write a method with this signature:
Public Sub SaveOption(Of T As ISerializable)(ByVal id As String, ByVal value As T)
or if you prefer C #:
public void SaveOption<T>(string id, T value) where T : ISerializable
That would be nice in principle, but what about types that have an attribute <Serializable>? The most noteworthy example of this is System.String, it does not implement ISerializable, but obviously this is the type I have to keep.
So, is there a way that I can limit which types are allowed in a method in compiletime, based on their attributes?