R
Richard Brown
I'm running into a big problem, and it's probably just my lack of C#
knowledge, but can someone give me a clue?
I'm using the folling object heirarchy:
AbstractViewContent -> Implements IViewContent interface
AbstractDatabaseView
TableEditorView
ProcedureEditorView
ViewEditorView
I have an implemented method call in a class ContentBinding,
IViewContent CreateViewContent(object obj)
that return TableEditorView, ProcedureEditorView or ViewEditorView depending
on the type of object.
(the IViewContent return type *cannot* be changed because it is part of a
library, I can only override the member method)
Now, in my other method,
void ObjectObject(AbstractDatabaseObject obj) {
ContentBinding binding = new ContentBinding();
AbstractDatabaseView content = (AbstractDatabaseView)
binding.CreateViewContent(obj);
content.Load(obj);
}
This compiles just fine, however, during runtime, I get an invalid type cast
exception on the second line!
Is it not possible to 'cast back down' from an implemented interface,
through the inheritance tree to a specifc child object?
I have traced the code, and, for the object I am trying to 'open', the
create view is TableEditorView.
knowledge, but can someone give me a clue?
I'm using the folling object heirarchy:
AbstractViewContent -> Implements IViewContent interface
AbstractDatabaseView
TableEditorView
ProcedureEditorView
ViewEditorView
I have an implemented method call in a class ContentBinding,
IViewContent CreateViewContent(object obj)
that return TableEditorView, ProcedureEditorView or ViewEditorView depending
on the type of object.
(the IViewContent return type *cannot* be changed because it is part of a
library, I can only override the member method)
Now, in my other method,
void ObjectObject(AbstractDatabaseObject obj) {
ContentBinding binding = new ContentBinding();
AbstractDatabaseView content = (AbstractDatabaseView)
binding.CreateViewContent(obj);
content.Load(obj);
}
This compiles just fine, however, during runtime, I get an invalid type cast
exception on the second line!
Is it not possible to 'cast back down' from an implemented interface,
through the inheritance tree to a specifc child object?
I have traced the code, and, for the object I am trying to 'open', the
create view is TableEditorView.