Thursday 15 July 2010

c# - How to specify a generic type should be marked with an attribute? -


I know that I can:

  public class sample class & lt; TSERIALABLE & gt; Where TSerializable: Iserializable  

How can I write a sample class which only accepts classes that are marked instead of SerializableAttribute?

You can not do this on the compiler, such as adding something to FxPP.

The best you can do at runtime (once), probably through a stable manufacturer who verifies the question in T and capturing your unit tests Gives an error to:

  Public class sample class  (); // fine new sample class  (); / / Fail}}  

No comments:

Post a Comment