Newtonsoft.Json.Bson.BsonWriter.WriteRegex C# (CSharp) Method

WriteRegex() public method

Writes a BSON regex.
public WriteRegex ( string pattern, string options ) : void
pattern string The regex pattern.
options string The regex options.
return void
        public void WriteRegex(string pattern, string options)
        {
            ValidationUtils.ArgumentNotNull(pattern, nameof(pattern));

            // hack to update the writer state
            UpdateScopeWithFinishedValue();
            AutoComplete(JsonToken.Undefined);
            AddToken(new BsonRegex(pattern, options));
        }
    }

Usage Example

コード例 #1
0
    private void WriteBson(BsonWriter writer, Regex regex)
    {
      // Regular expression - The first cstring is the regex pattern, the second
      // is the regex options string. Options are identified by characters, which 
      // must be stored in alphabetical order. Valid options are 'i' for case 
      // insensitive matching, 'm' for multiline matching, 'x' for verbose mode, 
      // 'l' to make \w, \W, etc. locale dependent, 's' for dotall mode 
      // ('.' matches everything), and 'u' to make \w, \W, etc. match unicode.

      string options = null;

      if (HasFlag(regex.Options, RegexOptions.IgnoreCase))
        options += "i";

      if (HasFlag(regex.Options, RegexOptions.Multiline))
        options += "m";

      if (HasFlag(regex.Options, RegexOptions.Singleline))
        options += "s";

      options += "u";

      if (HasFlag(regex.Options, RegexOptions.ExplicitCapture))
        options += "x";

      writer.WriteRegex(regex.ToString(), options);
    }
All Usage Examples Of Newtonsoft.Json.Bson.BsonWriter::WriteRegex