Example #1
0
 public static bool ContainsReference <TValue>(this ReadOnlyArray <TValue> array, TValue value)
     where TValue : class
 {
     return(IndexOfReference(array, value) != -1);
 }
Example #2
0
        private static NameAndParameters ParseNameAndParameters(string text, ref int index, bool nameOnly = false)
        {
            var textLength = text.Length;

            // Skip whitespace.
            while (index < textLength && char.IsWhiteSpace(text[index]))
            {
                ++index;
            }

            // Parse name.
            var nameStart = index;

            while (index < textLength)
            {
                var nextChar = text[index];
                if (nextChar == '(' || nextChar == NamedValue.Separator[0] || char.IsWhiteSpace(nextChar))
                {
                    break;
                }
                ++index;
            }
            if (index - nameStart == 0)
            {
                throw new ArgumentException($"Expecting name at position {nameStart} in '{text}'", nameof(text));
            }
            var name = text.Substring(nameStart, index - nameStart);

            if (nameOnly)
            {
                return new NameAndParameters {
                           name = name
                }
            }
            ;

            // Skip whitespace.
            while (index < textLength && char.IsWhiteSpace(text[index]))
            {
                ++index;
            }

            // Parse parameters.
            NamedValue[] parameters = null;
            if (index < textLength && text[index] == '(')
            {
                ++index;
                var closeParenIndex = text.IndexOf(')', index);
                if (closeParenIndex == -1)
                {
                    throw new ArgumentException($"Expecting ')' after '(' at position {index} in '{text}'", nameof(text));
                }

                var parameterString = text.Substring(index, closeParenIndex - index);
                parameters = NamedValue.ParseMultiple(parameterString);
                index      = closeParenIndex + 1;
            }

            if (index < textLength && (text[index] == ',' || text[index] == InputBinding.Separator))
            {
                ++index;
            }

            return(new NameAndParameters {
                name = name, parameters = new ReadOnlyArray <NamedValue>(parameters)
            });
        }
    }