public void ShouldThrowArgumentExceptionWhenOneOrMoreElementsAreNull() {
      Assert.Throws<ArgumentException>(delegate()
      {
        ParameterizedStringPart[] parts = new ParameterizedStringPart[2];
        parts[0] = new ParameterizedStringPartParameter("name");
        parts[1] = null;

        ParameterizedString s =
          ParameterizedString.FromParameterizedStringPartCollection(parts, "$");
      });
    }
Ejemplo n.º 2
0
        public void ShouldThrowArgumentExceptionWhenOneOrMoreElementsAreNull()
        {
            Assert.Throws <ArgumentException>(delegate()
            {
                ParameterizedStringPart[] parts = new ParameterizedStringPart[2];
                parts[0] = new ParameterizedStringPartParameter("name");
                parts[1] = null;

                ParameterizedString s =
                    ParameterizedString.FromParameterizedStringPartCollection(parts, "$");
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a value that indicates whether the provided object is equal to
        /// this object.
        /// </summary>
        /// <param name="obj">
        /// An object that can be cast to a <see cref="ParameterizedStringPartLiteral"/>
        /// object.
        /// </param>
        /// <returns>
        /// <c>true</c> if the provided object is equals to this object; otherwise,
        /// <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            ParameterizedStringPartParameter p =
                obj as ParameterizedStringPartParameter;

            if ((object)p == null)
            {
                return(false);
            }

            return(p.name == name);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Parses a string extracting the paramters and literal parts.
    /// </summary>
    public virtual void Parse() {
      int begin, end, length, i = 0;
      length = flat_string.Length;

      while (i < length) {
        // get the paramater begin position, note that spaces could be
        // only used as parameter terminator.
        begin = NextDelimiterPos(
          flat_string, delimiter_, false, i);

        // no delimiter was found after position "i", put the last
        // literal into the stack.
        if (begin == -1) {
          parts_.Add(
            new ParameterizedStringPartLiteral(flat_string.Substring(i)));
          break;
        }

        // save the literal part that comes before the starting delimiter,
        // if it exists.
        if (begin - i > 0) {
          parts_.Add(
            new ParameterizedStringPartLiteral(
              flat_string.Substring(i, begin - i)));
        }

        i = begin + delimiter_.Length; // next character after delimiter
        end = NextDelimiterPos(
          flat_string, delimiter_, use_space_as_terminator, i);

        // If the start delimiter is found but the end not, the string part
        // is a literal. The string part must have at least one character
        // between delimiters to be considered as a parameter.
        if (end == -1 || end - begin - delimiter_.Length == 0) {
          // the delimiters are not part of the parameters, but it is not a
          // parameter and we need to include the delimiter into it, so the
          // "i" pointer must be decremented by len(delimiter).
          parts_.Add(
            new ParameterizedStringPartLiteral(
              flat_string.Substring(i - delimiter_.Length)));
          break;
        }

        // point "i" to next character after delimiter, not consider
        // spaces.
        if (use_space_as_terminator && end < flat_string.Length &&
          flat_string[end] == ' ') {
          i = end;
        } else {
          i = end + delimiter_.Length;
        }

        ParameterizedStringPartParameter part =
          new ParameterizedStringPartParameter(
            flat_string.Substring(
              begin + delimiter_.Length, end - begin - delimiter_.Length),
            string.Empty);
        parts_.Add(part);
        parameters_.AddIfAbsent(part);
      }
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Parses a string extracting the paramters and literal parts.
        /// </summary>
        public virtual void Parse()
        {
            int begin, end, length, i = 0;

            length = flat_string.Length;

            while (i < length)
            {
                // get the paramater begin position, note that spaces could be
                // only used as parameter terminator.
                begin = NextDelimiterPos(
                    flat_string, delimiter_, false, i);

                // no delimiter was found after position "i", put the last
                // literal into the stack.
                if (begin == -1)
                {
                    parts_.Add(
                        new ParameterizedStringPartLiteral(flat_string.Substring(i)));
                    break;
                }

                // save the literal part that comes before the starting delimiter,
                // if it exists.
                if (begin - i > 0)
                {
                    parts_.Add(
                        new ParameterizedStringPartLiteral(
                            flat_string.Substring(i, begin - i)));
                }

                i   = begin + delimiter_.Length; // next character after delimiter
                end = NextDelimiterPos(
                    flat_string, delimiter_, use_space_as_terminator, i);

                // If the start delimiter is found but the end not, the string part
                // is a literal. The string part must have at least one character
                // between delimiters to be considered as a parameter.
                if (end == -1 || end - begin - delimiter_.Length == 0)
                {
                    // the delimiters are not part of the parameters, but it is not a
                    // parameter and we need to include the delimiter into it, so the
                    // "i" pointer must be decremented by len(delimiter).
                    parts_.Add(
                        new ParameterizedStringPartLiteral(
                            flat_string.Substring(i - delimiter_.Length)));
                    break;
                }

                // point "i" to next character after delimiter, not consider
                // spaces.
                if (use_space_as_terminator && end < flat_string.Length &&
                    flat_string[end] == ' ')
                {
                    i = end;
                }
                else
                {
                    i = end + delimiter_.Length;
                }

                ParameterizedStringPartParameter part =
                    new ParameterizedStringPartParameter(
                        flat_string.Substring(
                            begin + delimiter_.Length, end - begin - delimiter_.Length),
                        string.Empty);
                parts_.Add(part);
                parameters_.AddIfAbsent(part);
            }
        }