In C#, is it possible to use a handwritten interface for a dynamic var? I'm interfacing with an app using COM automation, and although I can access properties like this:
dynamic shape = comObject;
int Width = (int)shape.Width;
..I would really prefer to use this:
interface PageShape {
int Width {get; set;}
int Height {get; set;}
}
PageShape shape2 = (PageShape)comObject;
int Width = shape.Width; // COOL!
Is this possible? This typically triggers an InvalidCastException
, but I'm just curious to see if its possible. More details on my specific scenario here.