Possible Duplicate:
Interface defining a constructor signature?
I have a mixed hierarchy of classes and interfaces.
For using serialisation I need a default constructor present in
each class. I would really aprreciate if the compiler could tell
me that a default constructor is missing somewhere in the hierarchy.
(seeing the problem at compile time, not in the later tests)
What I would like to have could be some markup or attribute,
but I could not find anything.
Something like:
[ForceDefaultConstructor]
interface IVeryQuickSerializable
{
Serialize();
Deserialize();
}
would be great!
But anything like that is very appreciated.
There is a limitation: I cannot change the Serialisation.
Making it generic would solve the problem, but I do not have
the source. Writing a wrapper might do the job, but it will
have a loophole for objects deriving from the toplevel Serialisation
interface (which may not be altered).
You can’t do that in an interface or attribute.
Two thoughts:
expose your serialization code in a generic API that uses the
T : new()clause, i.e.