Esempio n. 1
0
        internal static bool TryParse(string str, out CADColor result)
        {
            string[] arr = str.Split(':');
            if (arr.Length != 2)
            {
                result = CADColor.ByLayer;
                return(false);
            }

            //
            ColorMethod colorMethod = (ColorMethod)Enum.Parse(typeof(ColorMethod), arr[0], true);

            //
            string[] rgb = arr[1].Split(',');
            if (rgb.Length != 3)
            {
                result = CADColor.ByLayer;
                return(false);
            }

            byte red   = 0;
            byte green = 0;
            byte blue  = 0;

            if (byte.TryParse(rgb[0], out red) &&
                byte.TryParse(rgb[1], out green) &&
                byte.TryParse(rgb[2], out blue))
            {
                result             = new CADColor();
                result.colorMethod = colorMethod;
                result.r           = red;
                result.g           = green;
                result.b           = blue;

                return(true);
            }
            else
            {
                result = CADColor.ByLayer;
                return(false);
            }
        }
Esempio n. 2
0
        public bool Equals(CADColor rhs)
        {
            if (colorMethod != rhs.colorMethod)
            {
                return(false);
            }

            switch (colorMethod)
            {
            case ColorMethod.ByColor:
                return(r == rhs.r &&
                       g == rhs.g &&
                       b == rhs.b);

            case ColorMethod.ByBlock:
            case ColorMethod.ByLayer:
            case ColorMethod.None:
            default:
                return(true);
            }
        }