Represents serialization options for a Dictionary value.
Inheritance: BsonBaseSerializationOptions
 /// <summary>
 /// Initializes a new instance of the DictionarySerializer class.
 /// </summary>
 /// <param name="defaultSerializationOptions">The default serialization options.</param>
 public DictionarySerializer(DictionarySerializationOptions defaultSerializationOptions)
     : base(defaultSerializationOptions)
 {
     _keyValuePairSerializer = new KeyValuePairSerializer<object, object>();
 }
 /// <summary>
 /// Initializes a new instance of the NameValueCollectionSerializer class.
 /// </summary>
 /// <param name="defaultSerializationOptions">The default serialization options.</param>
 public NameValueCollectionSerializer(DictionarySerializationOptions defaultSerializationOptions)
     : base(defaultSerializationOptions)
 {
     //_keyValuePairSerializer = new KeyValuePairSerializer<object, object>();
     _keyValuePairSerializer = new KeyValuePairSerializer<string, string>();
 }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
 public static void Test_Serialize_04(DictionaryRepresentation dictionaryRepresentation)
 {
     Trace.WriteLine("BsonPBSerializationProvider.RegisterProvider()");
     BsonPBSerializationProvider.RegisterProvider();
     PBDictionarySerializer.RegisterGenericDictionarySerializer();
     try
     {
         //PBDictionarySerializer.DefaultDictionaryRepresentation = dictionaryRepresentation;
         DictionarySerializationOptions options = new DictionarySerializationOptions(dictionaryRepresentation);
         Dictionary<string, ZValue> infos2 = Create_Dictionary_string_ZValue_01();
         //BsonDocument document = infos2.zToBsonDocument(options);
         //Trace.WriteLine(document.zToJson());
         Trace.WriteLine("dictionaryRepresentation : {0}", dictionaryRepresentation);
         string json = infos2.ToJson(options);
         Trace.WriteLine(json);
     }
     finally
     {
         Trace.WriteLine("BsonPBSerializationProvider.UnregisterProvider()");
         BsonPBSerializationProvider.UnregisterProvider();
         PBDictionarySerializer.UnregisterGenericDictionarySerializer();
     }
 }
Esempio n. 5
0
        //public static Download.Print.RapideDdl.RapideDdl_PostDetail Create_RapideDdl_PostDetail_01()
        //{
        //    return new Download.Print.RapideDdl.RapideDdl_PostDetail
        //    {
        //        sourceUrl = "http://zozo.com",
        //        loadFromWebDate = DateTime.Now,
        //        creationDate = DateTime.Now,
        //        postAuthor = "toto",
        //        title = "tutu",
        //        category = "tata",
        //        language = "titi",
        //        size = "zaza",
        //        nbPages = 5,
        //        description = new string[] { "nana", "nono", "nini" },
        //        infos = new NamedValues<ZValue> { { "gaga", "gogo" }, { "gigi", "gugu" } },
        //        //images = new List<ImageHtml> { new ImageHtml { Source = "http://baba.com/1234" }, new ImageHtml { Source = "http://baba.com/5678" } },
        //        images = new UrlImage[] { new UrlImage("http://baba.com/1234"), new UrlImage("http://baba.com/5678") },
        //        downloadLinks = new string[] { "http://zozo.com/1234", "http://zozo.com/5678" }
        //    };
        //}

        //public static Download.Print.RapideDdl.RapideDdl_PostDetail Create_RapideDdl_PostDetail_02()
        //{
        //    return new Download.Print.RapideDdl.RapideDdl_PostDetail
        //    {
        //        sourceUrl = "http://zozo.com",
        //        loadFromWebDate = DateTime.Now,
        //        creationDate = DateTime.Now,
        //        postAuthor = "toto",
        //        title = "tutu",
        //        category = "tata",
        //        language = "titi",
        //        size = "zaza",
        //        nbPages = 5,
        //        description = new string[] { "nana", "nono", "nini" },
        //        infos = new NamedValues<ZValue> { { "gaga.", "gogo" }, { "gigi", "gugu" } },
        //        //images = new List<ImageHtml> { new ImageHtml { Source = "http://baba.com/1234" }, new ImageHtml { Source = "http://baba.com/5678" } },
        //        images = new UrlImage[] { new UrlImage("http://baba.com/1234"), new UrlImage("http://baba.com/5678") },
        //        downloadLinks = new string[] { "http://zozo.com/1234", "http://zozo.com/5678" }
        //    };
        //}

        public static void RegisterClassMap_Test_Bson_Class_01_01(DictionarySerializationOptions dictionarySerializationOptions)
        {
            if (BsonClassMap.IsClassMapRegistered(typeof(Test_Bson_Class_01)))
            {
                //BsonClassMap map = BsonClassMap.LookupClassMap(typeof(Test_Bson_Class_01));
                //Trace.WriteLine("change existing class map");
                //BsonMemberMap memberMap = map.GetMemberMap("infos1NamedValuesZValue");
                //memberMap.SetSerializationOptions(DictionarySerializationOptions.ArrayOfDocuments);
                Trace.WriteLine("error class map Test_Bson_Class_01 is already registered");
            }
            else
            {
                Trace.WriteLine("register class map Test_Bson_Class_01 : dictionarySerializationOptions {0}", dictionarySerializationOptions);
                BsonClassMap.RegisterClassMap<Test_Bson_Class_01>(cm =>
                {
                    cm.AutoMap();
                    //cm.GetMemberMap(c => c.infos3DictionaryStringBsonValue).SetSerializationOptions(DictionarySerializationOptions.ArrayOfArrays);
                    cm.GetMemberMap(c => c.infos1NamedValuesZValue).SetSerializationOptions(dictionarySerializationOptions);
                    cm.GetMemberMap(c => c.infos2DictionaryStringZValue).SetSerializationOptions(dictionarySerializationOptions);
                    cm.GetMemberMap(c => c.infos3DictionaryStringBsonValue).SetSerializationOptions(dictionarySerializationOptions);
                });
            }
            Trace.WriteLine();
        }