我相信你只是不想下列測試執行操作:
所以你可能只需要添加在您的測試回報。
休息不會幫助你「走出方法」,它只是爲了開關。
private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.Source;
if(button.Label.ToString() == "Koala2")
{
KinectTileButton_Click_1(sender, e);
return;//get out of this method.
}
var wineModel = button.Tag as WineModel;
var selectionDisplay = new SelectionDisplay(wineModel);
this.kinectRegionGrid.Children.Add(selectionDisplay);
e.Handled = true;
}
或使用的if/else
private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.Source;
if(button.Label.ToString() == "Koala2")
KinectTileButton_Click_1(sender, e);
else
{
var wineModel = button.Tag as WineModel;
var selectionDisplay = new SelectionDisplay(wineModel);
this.kinectRegionGrid.Children.Add(selectionDisplay);
}
e.Handled = true;
}
順便說一下,這將是可能更清潔做的(好吧,我喜歡小方法)
private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.Source;
if(button.Label.ToString() == "Koala2")
Method1(<somearguments>);
else
Method2(button.Tag as WineModel);
e.Handled = true;//if it must happen for all label values.
}
public void Method1(<some parameters>) {
//DoSomething
}
public void Method2(WineModel wineModel) {
var selectionDisplay = new SelectionDisplay(wineModel);
this.kinectRegionGrid.Children.Add(selectionDisplay);
}
爲什麼不直接使用如果陳述?當您僅對一種情況進行測試時,如果有開關/情況說明沒有多大意義。你期望發生什麼?怎麼了? –
同意@SavannaKing,你是什麼意思「2行爲發生」?我不明白你期望發生什麼以及實際發生了什麼。 – BradleyDotNET
發生什麼「2行動」?你的問題沒有多大意義。 –