(A) Speaking strictly, nope, there's no way. After you make a cast, you're left with a temporary value of a different type - and almost no syntax branches are left after the cast, be it normal cast or the AS operator. You must either parenthesize it and immediatelly use it, or you must store it in a variable.
(B) Speaking loosely, there's a way: just do not make the cast at all. But be informed that it will:
- require the newer .Net platform
- be less safe (compile time name checks are OFF)
- be even less safe (runtime TYPE checks are off, if property-name is found then it used, regardless of what exact obejct type you had in the variable)
- has a bit worse performance (simply, dynamic ops are slower than compiled ones)
well, and as I said dynamic, it uses the CLR4.0 dynamic expression:
private void MyButton_Clicked(object sender, RoutedEventtArgs e)
{
dynamic tmp = sender;
tmp.Projection.RotationX = 20;
}
But, I really don't suggest doing it just to skip some parenthesis.. There is ZERO type checking in this expression. It is 100% duck typing. For a Button, it is OK, as the API of the button is really not likely to change. But for your own code which will often mutate, be careful - or include proper unit tests for property existence.