I was wondering if there was a way to cast a interface property in a derived class, for example:
public interface IImageGenerator
{
object FinalImage { get; set; }
}
public MyClass : IImageGenerator
{
public Image FinalImage{ get;set; } // Its cast as Image instead of Object
}
If things are setup in the interface as objects I have to do FinalImage as Image all over the place and was wondering if there was a way to not do that. The only other thing I can think is to create a property in the derived class that returns the interface property as a Image representation e.g.
public Image MyCastProperty
{
get {return FinalImage as Image;}
}
You can do this:
Alternative – and preferably – make the interface generic:
Do you really need
IImageGeneratorto have a setter in the property though? That doesn’t sound like something I’d expect for a generator.