本文整理汇总了C#中MongoDB.Bson.IO.BsonBinaryWriter.PushElementNameValidator方法的典型用法代码示例。如果您正苦于以下问题:C# BsonBinaryWriter.PushElementNameValidator方法的具体用法?C# BsonBinaryWriter.PushElementNameValidator怎么用?C# BsonBinaryWriter.PushElementNameValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonBinaryWriter
的用法示例。
在下文中一共展示了BsonBinaryWriter.PushElementNameValidator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInvalidKeys
public void TestInvalidKeys(string key)
{
var c = new C { Id = 1, D = new Hashtable { { key, 2 } }, G = new Dictionary<object, int> { { key, 3 } } };
using (var stream = new MemoryStream())
using (var bsonWriter = new BsonBinaryWriter(stream, BsonBinaryWriterSettings.Defaults))
{
bsonWriter.PushElementNameValidator(CollectionElementNameValidator.Instance);
Assert.Throws<BsonSerializationException>(() => BsonSerializer.Serialize(bsonWriter, c));
}
}
示例2: WriteUpdate
private void WriteUpdate(BsonBinaryWriter binaryWriter, BsonDocument update, IElementNameValidator updateValidator)
{
binaryWriter.PushElementNameValidator(updateValidator);
try
{
var position = binaryWriter.BaseStream.Position;
var context = BsonSerializationContext.CreateRoot(binaryWriter);
BsonDocumentSerializer.Instance.Serialize(context, update);
if (updateValidator is UpdateElementNameValidator && binaryWriter.BaseStream.Position == position + 5)
{
throw new BsonSerializationException("Update documents cannot be empty.");
}
}
finally
{
binaryWriter.PopElementNameValidator();
}
}
示例3: SerializeUpdate
private void SerializeUpdate(BsonBinaryWriter bsonWriter, BsonDocument update)
{
var updateValidator = new UpdateOrReplacementElementNameValidator();
bsonWriter.PushElementNameValidator(updateValidator);
try
{
var context = BsonSerializationContext.CreateRoot<BsonDocument>(bsonWriter);
BsonDocumentSerializer.Instance.Serialize(context, update);
}
finally
{
bsonWriter.PopElementNameValidator();
}
}
示例4: WriteQuery
private void WriteQuery(BsonBinaryWriter binaryWriter, BsonDocument query, IElementNameValidator queryValidator)
{
binaryWriter.PushElementNameValidator(queryValidator);
try
{
var context = BsonSerializationContext.CreateRoot(binaryWriter);
BsonDocumentSerializer.Instance.Serialize(context, query ?? new BsonDocument());
}
finally
{
binaryWriter.PopElementNameValidator();
}
}
示例5: SerializeUpdate
private void SerializeUpdate(BsonBinaryWriter bsonWriter, BsonDocument update, UpdateType updateType)
{
bsonWriter.PushElementNameValidator(ElementNameValidatorFactory.ForUpdateType(updateType));
try
{
var position = bsonWriter.BaseStream.Position;
var context = BsonSerializationContext.CreateRoot(bsonWriter);
BsonDocumentSerializer.Instance.Serialize(context, update);
if (updateType == UpdateType.Update && bsonWriter.BaseStream.Position == position + 8)
{
throw new BsonSerializationException("Update documents cannot be empty.");
}
}
finally
{
bsonWriter.PopElementNameValidator();
}
}
示例6: SerializeUpdate
private void SerializeUpdate(BsonBinaryWriter bsonWriter, BsonDocument update, UpdateType updateType)
{
bsonWriter.PushElementNameValidator(ElementNameValidatorFactory.ForUpdateType(updateType));
try
{
var context = BsonSerializationContext.CreateRoot<BsonDocument>(bsonWriter);
BsonDocumentSerializer.Instance.Serialize(context, update);
}
finally
{
bsonWriter.PopElementNameValidator();
}
}