Anyway, I have a method, say it looks like this:
public void Initialize(Device device);
Now, I have a class implementing an interface for abstraction, like this:
public interface IGraphicsDevice
{
Device Device { get; }
}
public class GraphicsDevice : IGraphicsDevice
{
private Device device;
...
public Device Device
{
get { return device; }
}
}
Since I only work with interfaces and not classes directly, I would call the Initialize method like this:
IGraphicsDevice graphicsDevice; Initialize(graphicsDevice.Device);
Now, for the problem. I don't really want to expose the Device class from my interface. I would like to have a custom implicit cast so I could call the method just like this:
IGraphicsDevice graphicsDevice; Initialize(graphicsDevice);
If I didn't use only interfaces, I could do it like this in the GraphicsDevice class...
public static implicit operator Device(GraphicsDevice graphicsDevice)
{
return graphicsDevice.Device;
}
... and the call to Initialize would simply pass through without a problem. But is it possible to do this some way through interfaces? The compiler tells me interfaces cannot have operators. Does that mean there is no way to create an implicit cast from an interface to another class?
Thanks in advance!

New Topic/Question
Reply




MultiQuote




|