private static void ParseTolerance(string bandDColor)
        {
            if (bandDColor == null)
            {
                throw new ArgumentNullException(nameof(bandDColor));
            }

            if (!ColorBand.TryParse(bandDColor, out var colorBandD))
            {
                throw new ArgumentException($"unable to parse: {bandDColor}", nameof(bandDColor));
            }
        }
        private static int ParseMultiplier(string bandCColor)
        {
            if (bandCColor == null)
            {
                throw new ArgumentNullException(nameof(bandCColor));
            }

            if (!ColorBand.TryParse(bandCColor, out var colorBandC))
            {
                throw new ArgumentException($"unable to parse: {bandCColor}", nameof(bandCColor));
            }

            return(colorBandC.Multiplier);
        }
        private static int ParseSecondSignificantFigure(string bandBColor)
        {
            if (bandBColor == null)
            {
                throw new ArgumentNullException(nameof(bandBColor));
            }

            if (!ColorBand.TryParse(bandBColor, out var colorBandB))
            {
                throw new ArgumentException($"unable to parse: {bandBColor}", nameof(bandBColor));
            }
            else if (colorBandB == ColorBand.Pink || colorBandB == ColorBand.Silver || colorBandB == ColorBand.Gold)
            {
                throw new ArgumentException($"invalid color for second significant figure: {bandBColor}", nameof(bandBColor));
            }

            return(colorBandB.SignificantFigure.Value);
        }
示例#4
0
        public static bool TryParse(string input, out ColorBand colorBand)
        {
            colorBand = null;
            if (input == null)
            {
                return(false);
            }

            switch (input.Trim().ToLower())
            {
            case "pink":
            case "pk":
                colorBand = ColorBand.Pink;
                return(true);

            case "silver":
            case "sr":
                colorBand = ColorBand.Silver;
                return(true);

            case "gold":
            case "gd":
                colorBand = ColorBand.Gold;
                return(true);

            case "black":
            case "bk":
                colorBand = ColorBand.Black;
                return(true);

            case "brown":
            case "bn":
                colorBand = ColorBand.Brown;
                return(true);

            case "red":
            case "rd":
                colorBand = ColorBand.Red;
                return(true);

            case "orange":
            case "og":
                colorBand = ColorBand.Orange;
                return(true);

            case "yellow":
            case "ye":
                colorBand = ColorBand.Yellow;
                return(true);

            case "green":
            case "gn":
                colorBand = ColorBand.Green;
                return(true);

            case "blue":
            case "bu":
                colorBand = ColorBand.Blue;
                return(true);

            case "violet":
            case "vt":
                colorBand = ColorBand.Violet;
                return(true);

            case "grey":
            case "gy":
                colorBand = ColorBand.Grey;
                return(true);

            case "white":
            case "wh":
                colorBand = ColorBand.White;
                return(true);

            default:
                return(false);
            }
        }