/// <summary> /// Writes the name of an element to the writer. /// </summary> /// <param name="name">The name of the element.</param> public virtual void WriteName(string name) { if (name == null) { throw new ArgumentNullException("name"); } if (name.IndexOf('\0') != -1) { throw new BsonSerializationException("Element names cannot contain nulls."); } if (_disposed) { throw new ObjectDisposedException(this.GetType().Name); } if (_state != BsonWriterState.Name) { ThrowInvalidState("WriteName", BsonWriterState.Name); } if (!_elementNameValidator.IsValidElementName(name)) { var message = string.Format("Element name '{0}' is not valid'.", name); throw new BsonSerializationException(message); } _childElementNameValidatorFactory = () => _elementNameValidator.GetValidatorForChildContent(name); _name = name; _state = BsonWriterState.Value; }
/// <inheritdoc/> public bool IsValidElementName(string elementName) { // the first elementName we see determines whether we are validating an update or a replacement document if (_chosenValidator == null) { if (elementName.Length > 0 && elementName[0] == '$') { _chosenValidator = UpdateElementNameValidator.Instance;; } else { _chosenValidator = CollectionElementNameValidator.Instance; } } return(_chosenValidator.IsValidElementName(elementName)); }
public bool IsValidElementNameArray() => elementNameValidatorArray.IsValidElementName(elementName);
public bool IsValidElementNameHashSet() => elementNameValidatorHashSet.IsValidElementName(elementName);
public bool IsValidElementNameOriginal() => elementNameValidator.IsValidElementName(elementName);