Net generic constraints and object inheritance compiling issue?

It seems to me that you're missing an interface: public interface ISerializerBase { } public class SerializerBase : ISerializerBase { } public class DirectChild : SerializerBase { } public class InheritedChild : DirectChild, ISerializerBase { } public class panelGenericIOGrid where T: ISerializerBase, new() { } I don't know how that will change your design though. It might be that you'll need to reimplement some inherited methods or some interface methods in the InheritedChild But, maybe you can do this otherwise : public interface MSerializable {} public static class Serializable { public static void Serialize(this MSerializable self, string fileName) { // self will refer to the right type, // no need to use generics if all you want is to serialize it ... } } public class DirectChild : MSerializable { } public class InheritedChild : DirectChild { } public class panelGenericIOGrid where T: MSerializable, new() { } Will you do a binary serialization, or will you serialize it to XML?

It seems to me that you're missing an interface: public interface ISerializerBase { } public class SerializerBase : ISerializerBase { } public class DirectChild : SerializerBase { } public class InheritedChild : DirectChild, ISerializerBase { } public class panelGenericIOGrid where T: ISerializerBase, new() { } I don't know how that will change your design though. It might be that you'll need to reimplement some inherited methods or some interface methods in the InheritedChild. But, maybe you can do this otherwise: public interface MSerializable {} public static class Serializable { public static void Serialize(this MSerializable self, string fileName) { // self will refer to the right type, // no need to use generics if all you want is to serialize it ... } } public class DirectChild : MSerializable { } public class InheritedChild : DirectChild { } public class panelGenericIOGrid where T: MSerializable, new() { } Will you do a binary serialization, or will you serialize it to XML?

I think the interface is the best way to go. Its going to be some extra code, but since every method in BaseSerializer is static, its not too much extra work. Thanks!

– greggorob64 Aug 9 '10 at 18:28 If every method is static, I think you should really go with the mixin approach.... Inheritance doesn't make sense in this case, since you cannot have static methods in an interface and you can't implement interface methods with static ones. – Jordão Aug 9 '10 at 18:30.

The problem is that InheritedChild doesn't implement SerializerBase, so it doesn't fulfil the constraints for T in panelGenericIOGrid. Unfortunately it's not clear that the solution is meant to be as we don't know what you're trying to achieve. What are the members of SerializerBase in real life?

If you could give us more context, it would help us to help you.

See edit, I added some info – greggorob64 Aug 9 '10 at 18:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions