Hi,
I have a method:
public void StoreUsingKey<T>(T value) where T : class, new() {
var idModel = value as IIDModel;
if (idModel != null)
Store<T>(idModel);
AddToCacheUsingKey(value);
}
that I would like to optionally call the following method, based on the value
parameter's implementation of IIDModel
.
public void Store<T>(T value) where T : class, IIDModel, new() {
AddModelToCache(value);
}
Is there a way to tell Store<T>
that the value
parameter from StoreUsingKey<T>
implements IIDModel
? Or am I going about this the wrong way?
Rich
Answer
Removing the new()
constraint from each method allows the code to work. The problem was down to me trying to pass off an interface as an object which can be instantiated.