Example #1
0
        public static QuantityValue Parse(string text)
        {
            if (text == null)
            {
                throw Error.ArgumentNull("text");
            }

            string[] triple = text.SplitNotEscaped('|');

            if (triple.Length != 3)
            {
                throw Error.Argument("text", "Quantity needs to have three parts separated by '|'");
            }

            if (triple[0] == String.Empty)
            {
                throw new FormatException("Quantity needs to specify a number");
            }

            var number = PrimitiveTypeConverter.ConvertTo <Decimal>(triple[0]);
            var ns     = triple[1] != String.Empty ? StringValue.UnescapeString(triple[1]) : null;

            if (triple[2] == String.Empty)
            {
                throw new FormatException("Quantity needs to specify a unit");
            }

            var unit = StringValue.UnescapeString(triple[2]);

            return(new QuantityValue(number, ns, unit));
        }
Example #2
0
        public static TokenValue Parse(string text)
        {
            if (text == null)
            {
                throw Error.ArgumentNull("text");
            }

            string[] pair = text.SplitNotEscaped('|');

            if (pair.Length > 2)
            {
                throw Error.Argument("text", "Token cannot have more than two parts separated by '|'");
            }

            bool hasNamespace = pair.Length == 2;

            string pair0 = StringValue.UnescapeString(pair[0]);

            if (hasNamespace)
            {
                if (pair[1] == String.Empty)
                {
                    throw new FormatException("Token query parameters should at least specify a value after the '|'");
                }

                string pair1 = StringValue.UnescapeString(pair[1]);

                if (pair0 == String.Empty)
                {
                    return(new TokenValue(pair1, matchAnyNamespace: false));
                }
                else
                {
                    return(new TokenValue(pair1, pair0));
                }
            }
            else
            {
                return(new TokenValue(pair0, matchAnyNamespace: true));
            }
        }
Example #3
0
        public static ReferenceValue Parse(string text)
        {
            var value = StringValue.UnescapeString(text);

            return(new ReferenceValue(value));
        }