I’m building an application that supports plugins over a generic type of data. Problem is, I can’t seem to specify a generic condition that allows everything I need to pass through, here’s the details of the code:
abstract public class PluginObject<ManagedType>
abstract public class Plugin<EditedType> where EditedType : PluginObject<Object>
The <Object> here is the problem, when I create my classes and plugins, I’ll create models to handle the data aspect of the plugin. To this end, my first plugin has many items to manage and I can’t really create a sub class of them all, so I ended up create an interface IOrderObject that doesn’t contain anything.
Therefore, I ended up with:
SynchronizableObjectTripRouteTripRouteDirectionITripObject(Interface implemented into #2 and #3)
This way I can do:
public class RoutePluginObject<ManagedType> : Activis.Framework.Admin.PluginObject<ManagedType>
public class RouteManagementPlugin : Activis.Framework.Admin.Plugin<RoutePluginObject<Transdev.Limocar.iTripObject>>
And it is accepted, but the problem is that ITripObject is an interface not an object, so it can be converted to PluginObject<Object>.
So my question, is there a way to specify a condition that would allow something similar to this:
abstract public class Plugin<EditedType> where EditedType : PluginObject<Any>
This way, interfaces or objects could be provided by I don’t really care about this condition; all I want is that my Plugin‘s editedtype be a PluginObject of anything possible.
EDIT
Having better results with the covariance but still getting an error, i haven’t seen anything about the PluginObject inheritance in your examples (Matias), here is what i did:
public interface IPluginObject<out ManagedType>
abstract public class Plugin<EditedType> where EditedType : IPluginObject<EditedType>
public class RoutePluginObject : Activis.Framework.Admin.IPluginObject<TripRoute>
public class RouteManagementPlugin : Activis.Framework.Admin.Plugin<RoutePluginObject>
But i still get errors at the RouteManagementPlugin with:
The type ‘Transdev.Limocar.Admin.RoutePluginObject’ cannot be used as
type parameter ‘EditedType’ in the generic type or method
‘Activis.Framework.Admin.Plugin’. There is no implicit
reference conversion from ‘Transdev.Limocar.Admin.RoutePluginObject’
to
‘Activis.Framework.Admin.IPluginObject’
Unless i misunderstood covariance (which is probably the case) i seem to have followed your example clearly, still not getting it working…
You just need a second generic parameter: