Message 1 of 3
Why doesn't the implicit widening cast to Document work?

Not applicable
08-24-2016
09:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I've been working in the Inventor API (in C#) for some time and something that continues to bug me is that the widening cast from PartDocument, AssemblyDocument, etc to Document must be explicit. Everything that I have read leads me to believe that PartDocument is an interface that inherits from Document, so why do I get compile-time errors if I attempt:
Document doc = somePartDocument;
?
It sure would make writing more generic methods easier if the method signature could specify Document and I didn't have to explicitly cast every passed variable, or if actual generics could recognize that <T> where T : Document *includes* PartDocument, AssemblyDocument, etc.
Anyone else experience this, know why or happens or know a workaround?