Пример #1
0
        /// <summary>
        /// Constructor called by CssValue.GetCssValue()
        /// </summary>
        /// <param name="match">A Regex that matches a CssPrimitiveValue</param>
        /// <param name="readOnly">Specifiec if this instance is read-only</param>
        private CssPrimitiveValue(Match match, bool readOnly)
            : this(match.Value, readOnly)
        {
            if (match.Groups["func"].Success)
            {
                switch (match.Groups["funcname"].Value)
                {
                case "rect":
                    _primitiveType = CssPrimitiveType.Rect;
                    _rectValue     = new CssRect(match.Groups["funcvalue"].Value, ReadOnly);
                    break;

                case "attr":
                    _primitiveType = CssPrimitiveType.Attr;
                    _stringValue   = match.Groups["funcvalue"].Value;
                    break;

                case "url":
                    _stringValue   = match.Groups["funcvalue"].Value;
                    _primitiveType = CssPrimitiveType.Uri;
                    break;

                case "counter":
                    throw new NotImplementedException("Counters are not implemented");
                    //_primitiveType = CssPrimitiveType.CSS_COUNTER;
                }
            }
            else if (match.Groups["freqTimeNumber"].Success)
            {
                _floatValue = float.Parse(match.Groups["numberValue2"].Value, CssNumber.Format);

                switch (match.Groups["unit2"].Value)
                {
                case "Hz":
                    _primitiveType = CssPrimitiveType.Hz;
                    break;

                case "kHz":
                    _primitiveType = CssPrimitiveType.KHz;
                    break;

                case "in":
                    _primitiveType = CssPrimitiveType.In;
                    break;

                case "s":
                    _primitiveType = CssPrimitiveType.S;
                    break;

                case "ms":
                    _primitiveType = CssPrimitiveType.Ms;
                    break;

                case "%":
                    _primitiveType = CssPrimitiveType.Percentage;
                    break;

                default:
                    _primitiveType = CssPrimitiveType.Number;
                    break;
                }
            }
            else if (match.Groups["string"].Success)
            {
                _stringValue   = match.Groups["stringvalue"].Value;
                _primitiveType = CssPrimitiveType.String;
            }
            else if (match.Groups["colorIdent"].Success)
            {
                string val = match.Value;
                _stringValue   = match.Value;
                _primitiveType = CssPrimitiveType.Ident;
            }
            else
            {
                _primitiveType = CssPrimitiveType.Unknown;
            }
        }
        /// <summary>
        /// Constructor called by CssValue.GetCssValue()
        /// </summary>
        /// <param name="match">A Regex that matches a CssPrimitiveValue</param>
        /// <param name="readOnly">Specifiec if this instance is read-only</param>
        private CssPrimitiveValue(Match match, bool readOnly)
            : this(match.Value, readOnly)
        {
            if (match.Groups["func"].Success)
            {
                switch (match.Groups["funcname"].Value)
                {
                    case "rect":
                        _primitiveType = CssPrimitiveType.Rect;
                        rectValue = new CssRect(match.Groups["funcvalue"].Value, ReadOnly);
                        break;
                    case "attr":
                        _primitiveType = CssPrimitiveType.Attr;
                        stringValue = match.Groups["funcvalue"].Value;
                        break;
                    case "url":
                        stringValue = match.Groups["funcvalue"].Value;
                        _primitiveType = CssPrimitiveType.Uri;
                        break;
                    case "counter":
                        throw new NotImplementedException("Counters are not implemented");
                    //_primitiveType = CssPrimitiveType.CSS_COUNTER;
                }
            }
            else if (match.Groups["freqTimeNumber"].Success)
            {
                floatValue = Single.Parse(match.Groups["numberValue2"].Value, CssNumber.Format);

                switch (match.Groups["unit2"].Value)
                {
                    case "Hz":
                        _primitiveType = CssPrimitiveType.Hz;
                        break;
                    case "kHz":
                        _primitiveType = CssPrimitiveType.KHz;
                        break;
                    case "in":
                        _primitiveType = CssPrimitiveType.In;
                        break;
                    case "s":
                        _primitiveType = CssPrimitiveType.S;
                        break;
                    case "ms":
                        _primitiveType = CssPrimitiveType.Ms;
                        break;
                    case "%":
                        _primitiveType = CssPrimitiveType.Percentage;
                        break;
                    default:
                        _primitiveType = CssPrimitiveType.Number;
                        break;
                }
            }
            else if (match.Groups["string"].Success)
            {
                stringValue = match.Groups["stringvalue"].Value;
                _primitiveType = CssPrimitiveType.String;
            }
            else if (match.Groups["colorIdent"].Success)
            {
                string val = match.Value;
                stringValue = match.Value;
                _primitiveType = CssPrimitiveType.Ident;
            }
            else
            {
                _primitiveType = CssPrimitiveType.Unknown;
            }
        }