Can you clarify me why in this piece of code:
private Dictionary<Type, Type> viewTypeMap = new Dictionary<Type, Type>();
public void ShowView<TView>(ViewModelBase viewModel, bool showDialog = false)
where TView : IView
{
var view = Activator.CreateInstance(viewTypeMap[typeof(TView)]);
(IView)view.ShowDialog();
}
I get the error:
“Only assignment, call, increment, decrement, and new object
expressions can be used as a statement.”
IView defines the ShowDialog() method.
The cast operator is of lower precedence than the member access operator.
is parsed as
which is not a legal statement. You ought to write
if you mean to cast
BtoAand then callC()on typeA.For your future reference, the precedence table is here:
http://msdn.microsoft.com/en-us/library/aa691323(v=VS.71).aspx