public static void Test_PBBsonEnumerateValues_01() { BsonPBSerializationProvider.RegisterProvider(); try { Test_Bson_Class_01 test = Create_Test_Bson_Class_01(); BsonDocument document = test.zToBsonDocument(); Trace.WriteLine(document.zToJson()); Trace.WriteLine("start reader"); foreach (PBBsonNamedValue value in new PBBsonEnumerateValues(new PBBsonReaderWithBookmark(BsonReader.Create(document)))) { Trace.WriteLine("{0}: {1} ({2})", value.Name, value.Value, value.Value.BsonType); } } finally { //UnregisterBsonPBSerializationProvider(); BsonPBSerializationProvider.UnregisterProvider(); } }
public static void Test_Serialize_02(DictionaryRepresentation dictionaryRepresentation) { Trace.WriteLine("BsonPBSerializationProvider.RegisterProvider()"); BsonPBSerializationProvider.RegisterProvider(); PBDictionarySerializer.RegisterGenericDictionarySerializer(); try { Trace.WriteLine("set DefaultDictionaryRepresentation to {0}", dictionaryRepresentation); PBDictionarySerializer.DefaultDictionaryRepresentation = dictionaryRepresentation; Test_Bson_Class_01 test = Create_Test_Bson_Class_01(); BsonDocument document = test.zToBsonDocument(); Trace.WriteLine(document.zToJson()); } finally { Trace.WriteLine("BsonPBSerializationProvider.UnregisterProvider()"); BsonPBSerializationProvider.UnregisterProvider(); PBDictionarySerializer.UnregisterGenericDictionarySerializer(); } }
public static void Test_Serialize_01(DictionarySerializationOptions dictionarySerializationOptions) { //DictionarySerializationOptions.Document //DictionarySerializationOptions.ArrayOfDocuments //DictionarySerializationOptions.ArrayOfArrays Trace.WriteLine("BsonPBSerializationProvider.RegisterProvider()"); BsonPBSerializationProvider.RegisterProvider(); try { RegisterClassMap_Test_Bson_Class_01_01(dictionarySerializationOptions); // DictionarySerializationOptions.Defaults : Create and register a DictionarySerializer with the desired options instead. //BsonSerializer.RegisterGenericSerializerDefinition(); //Dictionary<string, string> dic = new Dictionary<string,string>(); //new Dictionary<string, string>().GetType().AssemblyQualifiedName; //DictionarySerializer //DictionarySerializationOptions.Defaults = DictionarySerializationOptions.Document; Test_Bson_Class_01 test = Create_Test_Bson_Class_01(); //BsonSerializer.Serialize<BsonDocument>(test); BsonDocument document = test.zToBsonDocument(); //Trace.WriteLine(test.zToJson()); Trace.WriteLine(document.zToJson()); //DataTable dt = document.zToDataTable2(); //Trace.WriteLine(); //Trace.WriteLine("table :"); //Trace.WriteLine(dt.zToString()); //RunSource.CurrentRunSource.SetResult(dt); //BsonDocument document = null; BsonValue value = document["toto"]; //value.IsBsonArray } finally { //UnregisterBsonPBSerializationProvider(); Trace.WriteLine("BsonPBSerializationProvider.UnregisterProvider()"); BsonPBSerializationProvider.UnregisterProvider(); } }
public static void Test_BsonReader_01() { BsonPBSerializationProvider.RegisterProvider(); try { Test_Bson_Class_01 test = Create_Test_Bson_Class_01(); BsonDocument document = test.zToBsonDocument(); Trace.WriteLine(document.zToJson()); Trace.WriteLine("start reader"); //BsonReader reader = BsonReader.Create(document); //BsonReader reader = BsonReader.Create(document.zToJson()); //PBBsonReader reader = new PBBsonReader(document); PBBsonReaderWithBookmark reader = new PBBsonReaderWithBookmark(BsonReader.Create(document)); while (reader.Read()) { if (RunSource.CurrentRunSource.IsExecutionAborted()) { break; } if (reader.Type == PBBsonReaderType.Value) { if (reader.Name != null) { Trace.Write("{0}: ", reader.Name); } Trace.WriteLine("{0} ({1})", reader.Value, reader.Value.BsonType); } else { Trace.WriteLine("{0}", reader.Type); } } } finally { //UnregisterBsonPBSerializationProvider(); BsonPBSerializationProvider.UnregisterProvider(); } }