示例#1
0
        public static bool TryParse(string s, out EntityColor color)
        {
            color = EntityColor.None;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            if (string.Compare(s, "by layer", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                color = EntityColor.ByLayer;
                return(true);
            }
            if (string.Compare(s, "by block", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                color = EntityColor.ByBlock;
                return(true);
            }
            if (string.Compare(s, "none", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                color = EntityColor.None;
                return(true);
            }
            if (string.Compare(s, "foreground", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                color = EntityColor.smethod_0(3305111552U);
                return(true);
            }
            Dictionary <string, string> properties = StringUtil.GetProperties(s);
            string    s1;
            ColorType result1;

            if (!properties.TryGetValue("color type", out s1) || !EnumUtil.TryParse <ColorType>(s1, true, out result1))
            {
                return(false);
            }
            switch (result1)
            {
            case ColorType.ByColor:
                string s2;
                int    result2;
                if (!properties.TryGetValue("rgb", out s2) || !int.TryParse(s2, NumberStyles.HexNumber, (IFormatProvider)CultureInfo.InvariantCulture, out result2))
                {
                    return(false);
                }
                color = EntityColor.CreateFromRgb(result2);
                break;

            case ColorType.ByColorIndex:
                string s3;
                short  result3;
                if (!properties.TryGetValue("index", out s3) || !short.TryParse(s3, out result3))
                {
                    return(false);
                }
                color = EntityColor.CreateFromColorIndex(result3);
                break;
            }
            return(true);
        }
示例#2
0
        public static EntityColor CreateFrom(ArgbColor color)
        {
            int   colorDifference;
            short colorIndex = DxfIndexedColorSet.GetColorIndex(color, out colorDifference);

            if (colorDifference != 0)
            {
                return(EntityColor.CreateFromRgb(color.Argb));
            }
            return(EntityColor.CreateFromColorIndex(colorIndex));
        }