As Adam R Harris you can use local variables to store data the code access more than once; in your code the variable most used is
sender cast to
DevExpress.Xpf.LayoutControl.GroupBox; the second one is its
Content property.
The followin is a possible arrangement:
var box = sender as DevExpress.Xpf.LayoutControl.GroupBox;
if (box != null)
{
var oldContent = box.Content;
var newContent = oldContent;
var emp = oldContent as Employee;
if (emp == null)
emp = oldContent as EmployeeMin;
if (box.State == DevExpress.Xpf.LayoutControl.GroupBoxState.Maximized)
{
newContent = new Employee(emp.user);
}
else
{
newContent = new EmployeeMin(emp.user);
}
if (newContent != oldContent)
box.Content = newContent;
}
I used
var to reduce type name appearance. There is only one instruction where you should explicitly put the type name, but I don't know it so I can't do it for you; I had sorrounded it with a block comment with
ContentType as the name of the type I don't know (maybe object, or
Employee or a base type).
Regards,
Daniele.