严谨逻辑处理
严谨逻辑处理很重要,对于不处理或错误的逻辑,要给与判断或列出分支,这样即使不好用,但不至于系统崩溃;否则,不但不好使,很可能系统崩溃
例如下面的严谨逻辑判断代码
示例(1)
private void ShowNavigateBall()
{
if (Host.Qyxy.Lpbz == "1")
{ circle.Visibility = Visibility.Visible;
dktj.Margin = new Thickness(0, 0, 5, 0);
smylr.Visibility = Visibility.Visible;
gxlr.Visibility = Visibility.Visible;
bglr.Visibility = Visibility.Visible;
sjlr.Visibility = Visibility.Visible;
smqlr.Visibility = Visibility.Visible;
sglr.Visibility = Host.Config.AppConfig.ShowSGLR ? Visibility.Visible : Visibility.Collapsed;
}
else if(Host.Qyxy.Lpbz=="0")//D级时
{ circle.Visibility = Visibility.Collapsed;
dktj.Margin = new Thickness(0, 0, 45, 0);
smylr.Visibility = Visibility.Visible;
gxlr.Visibility = Visibility.Collapsed;
bglr.Visibility = Visibility.Collapsed;
sjlr.Visibility = Visibility.Collapsed;
smqlr.Visibility = Visibility.Collapsed;
sglr.Visibility = Visibility.Visible;
}
else
{
Trace.Write("显示导航球时错误:连盘标识字段值为" + Host.Qyxy.Lpbz);
}
}
示例(2)
var count = items.Count();
//当小于或等于两个元素
if (count <= 2)
{
if (count == 2)
{
var elementLeft = items.ElementAt(0) as FrameworkElement;
if (elementLeft != null)
{
elementLeft.SetValue(Canvas.TopProperty, this.Height / 2 - elementLeft.Height / 2 - 15);
elementLeft.SetValue(Canvas.LeftProperty, 0d + 50);
}
//
var elementRight = items.ElementAt(1) as FrameworkElement;
if (elementRight != null)
{
elementRight.SetValue(Canvas.TopProperty, this.Height / 2 - elementRight.Height / 2 - 15);
elementRight.SetValue(Canvas.LeftProperty, this.Width - elementRight.Width);
}
}
}
else//其它
{
}