From 196db4c7303e4fd6507917a610137a6a9c5e8d9f Mon Sep 17 00:00:00 2001 From: GlenCFL Date: Fri, 7 Sep 2018 03:01:45 -0400 Subject: [PATCH] Use Enum.IsDefined as suggested. --- .../MinimapIconToCroppedBitmapConverter.cs | 48 +++++-------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/Filtration/Converters/MinimapIconToCroppedBitmapConverter.cs b/Filtration/Converters/MinimapIconToCroppedBitmapConverter.cs index 6b32d29..5b97bee 100644 --- a/Filtration/Converters/MinimapIconToCroppedBitmapConverter.cs +++ b/Filtration/Converters/MinimapIconToCroppedBitmapConverter.cs @@ -56,7 +56,7 @@ namespace Filtration.Converters Width = cellWidth, Height = cellHeight, X = column * cellWidth, - Y = row * cellWidth + Y = row * cellHeight }; bitmaps.Add(new CroppedBitmap(sourceImage, bitmapRect)); @@ -70,7 +70,8 @@ namespace Filtration.Converters { if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue || - values[2] == DependencyProperty.UnsetValue) { + values[2] == DependencyProperty.UnsetValue) + { return empty; } @@ -78,46 +79,23 @@ namespace Filtration.Converters var iconColor = (int)(values[1]); var iconShape = (int)(values[2]); - switch ((IconSize) iconSize) { - case IconSize.Largest: - case IconSize.Medium: - case IconSize.Small: - break; - default: - return empty; - } - - switch ((IconColor) iconColor) { - case IconColor.Blue: - case IconColor.Green: - case IconColor.Brown: - case IconColor.Red: - case IconColor.White: - case IconColor.Yellow: - break; - default: - return empty; - } - - switch ((IconShape) iconShape) { - case IconShape.Circle: - case IconShape.Diamond: - case IconShape.Hexagon: - case IconShape.Square: - case IconShape.Star: - case IconShape.Triangle: - break; - default: - return empty; + if (!Enum.IsDefined(typeof(IconSize), iconSize) || + !Enum.IsDefined(typeof(IconColor), iconColor) || + !Enum.IsDefined(typeof(IconShape), iconShape)) + { + return empty; } var shapeOffset = iconShape * (sizeCount * colorCount); var colorOffset = iconColor * sizeCount; var iconIndex = shapeOffset + colorOffset + iconSize; - if (iconIndex >= bitmaps.Count) { + if (iconIndex >= bitmaps.Count) + { return empty; - } else { + } + else + { return bitmaps[iconIndex]; } }