Source-CodeI’ve been writing my own serializer for a project that is a generic class. To instantiate it you must pass in a type T for all the generic magic to work. As I began refactoring this, I relized there *HAS* to be a .Net interface for serialization. A quick search later, and I have IFormatter, I already had the serialize and deserialize methods.

Great! now how do I use both generics and implement the interface? My existing code looked like

You can’t just tack on a comma and keep tacking things on, that would be in the context of the generic restrictions. My big hangup here was not realizing you can have more than one colon.

You need to use the format of:  public class ClassName<T> : IInterfaceName where T : Generic, Restriction, Items

Leave a Reply
Your email address will not be published.
  • ( will not be published )