当前位置: 首页>>代码示例>>C#>>正文


C# GeneralDTO类代码示例

本文整理汇总了C#中GeneralDTO的典型用法代码示例。如果您正苦于以下问题:C# GeneralDTO类的具体用法?C# GeneralDTO怎么用?C# GeneralDTO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GeneralDTO类属于命名空间,在下文中一共展示了GeneralDTO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MongoIgnored_Properties_Are_Ignored

        public void MongoIgnored_Properties_Are_Ignored()
        {
            var test = new GeneralDTO();
            test.IgnoredProperty = 42;
            var hydrated = BSONSerializer.Deserialize<GeneralDTO>(BSONSerializer.Serialize(test));

            Assert.AreEqual(0, hydrated.IgnoredProperty);
        }
开发者ID:sdether,项目名称:NoRM,代码行数:8,代码来源:BSONSerializerTest.cs

示例2: InsertFindDeleteBenchmark

        /// <summary>
        /// Inserts, finds one from the middle of the batch, then deletes from the specified collection.
        /// </summary>
        /// <param name="count"></param>
        private static void InsertFindDeleteBenchmark(int count)
        {
            MongoContext context = new MongoContext();
            var db = context.GetDatabase("benchmark");
            db.DropCollection("test");
            var coll = db.GetCollection<GeneralDTO>("test");
            coll.CreateIndex(new { Int = 1d }, false, "testIdx");

            OID oid = OID.EMPTY;
            DateTime start = DateTime.Now;

            List<GeneralDTO> cache = new List<GeneralDTO>(count);
            int toUse = (int)Math.Floor(count / 2f);
            for (int i = 0; i < count; i++)
            {
                var into = new GeneralDTO();
                into._id = OID.NewOID();
                into.Title = Guid.NewGuid().ToString();
                into.Int = i;
                if (i == toUse)
                {
                    oid = into._id;
                }
                cache.Add(into);
            }
            coll.Insert(cache);
            Console.WriteLine("Inserted {0} objects in {1}ms", count,
                (DateTime.Now - start).TotalMilliseconds);

            start = DateTime.Now;
            var first = coll.Find(new { _id = oid }).First();
            Console.WriteLine("   Search for 1 object in {1}ms", count,
                (DateTime.Now - start).TotalMilliseconds);

            start = DateTime.Now;
            //find something randomly using a regex.
            var numLessThan2 = coll.Find(new { Title = new Regex(".*8a.*", RegexOptions.IgnoreCase) }).ToArray().Count();
            Console.WriteLine("   Found {0} objects that match the regex. in {1}ms", numLessThan2,
                (DateTime.Now - start).TotalMilliseconds);

            start = DateTime.Now;
            coll.UpdateOne(new { _id = oid }, new { Int = M.Inc(5) });
            Console.WriteLine("   Updated that one in {0}ms",
                (DateTime.Now - start).TotalMilliseconds);

            start = DateTime.Now;
            first = coll.Find(new { _id = oid }).First();

            coll.Delete(new { Int = Q.LessThan(Int32.MaxValue) });
            Console.WriteLine("   Deleted {0} objects in {1}ms\r\n", count,
                (DateTime.Now - start).TotalMilliseconds);
        }
开发者ID:jasona,项目名称:NoRM,代码行数:56,代码来源:Program.cs

示例3: SerializationOfDoublesAreNotLossy

        public void SerializationOfDoublesAreNotLossy()
        {
            var obj1 = new GeneralDTO { Pi = 3.1415927d };
            var obj2 = new GeneralDTO { Pi = null };

            var obj1Bytes = BsonSerializer.Serialize(obj1);
            var obj2Bytes = BsonSerializer.Serialize(obj2);

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.Equal(obj1.Pi, hydratedObj1.Pi);
            Assert.Equal(null, hydratedObj2.Pi);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例4: SerializationOfEnumIsNotLossy

        public void SerializationOfEnumIsNotLossy()
        {
            var obj1 = new GeneralDTO{ Flags32 = Flags32.FlagOn, Flags64 = Flags64.FlagOff };
            var obj2 = new GeneralDTO();

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(BsonSerializer.Serialize(obj1));
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(BsonSerializer.Serialize(obj2));

            Assert.Equal(obj1.Flags32, hydratedObj1.Flags32);
            Assert.Equal(null, hydratedObj2.Flags32);

            Assert.Equal(obj1.Flags64, hydratedObj1.Flags64);
            Assert.Equal(null, hydratedObj2.Flags64);
        }
开发者ID:gaoninggn,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例5: Serialization_Of_Bytes_Is_Not_Lossy

        public void Serialization_Of_Bytes_Is_Not_Lossy()
        {
            var obj1 = new GeneralDTO { Bytes = BitConverter.GetBytes(Int32.MaxValue) };
            var obj2 = new GeneralDTO { Bytes = null };

            var obj1Bytes = BSONSerializer.Serialize(obj1);
            var obj2Bytes = BSONSerializer.Serialize(obj2);

            var hydratedObj1 = BSONSerializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BSONSerializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.AreEqual(obj1.Bytes, hydratedObj1.Bytes);
            Assert.AreEqual(null, hydratedObj2.Bytes);
        }
开发者ID:sdether,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例6: Serialization_Of_Booleans_Are_Not_Lossy

        public void Serialization_Of_Booleans_Are_Not_Lossy()
        {
            var obj1 = new GeneralDTO { ABoolean = true };
            var obj2 = new GeneralDTO { ABoolean = null };

            var obj1Bytes = BSONSerializer.Serialize(obj1);
            var obj2Bytes = BSONSerializer.Serialize(obj2);

            var hydratedObj1 = BSONSerializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BSONSerializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.AreEqual(obj1.ABoolean, hydratedObj1.ABoolean);
            Assert.AreEqual(null, hydratedObj2.ABoolean);
        }
开发者ID:sdether,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例7: SerializationOfBooleansAreNotLossy

        public void SerializationOfBooleansAreNotLossy()
        {
            var obj1 = new GeneralDTO { ABoolean = true };
            var obj2 = new GeneralDTO { ABoolean = null };

            var obj1Bytes = BsonSerializer.Serialize(obj1);
            var obj2Bytes = BsonSerializer.Serialize(obj2);

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.Equal(obj1.ABoolean, hydratedObj1.ABoolean);
            Assert.Equal(null, hydratedObj2.ABoolean);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例8: SerializationOfBytesIsNotLossy

        public void SerializationOfBytesIsNotLossy()
        {
            var obj1 = new GeneralDTO { Bytes = BitConverter.GetBytes(Int32.MaxValue) };
            var obj2 = new GeneralDTO { Bytes = null };

            var obj1Bytes = BsonSerializer.Serialize(obj1);
            var obj2Bytes = BsonSerializer.Serialize(obj2);

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.Equal(obj1.Bytes, hydratedObj1.Bytes);
            Assert.Equal(null, hydratedObj2.Bytes);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例9: Serialization_Of_Dates_Has_Millisecond_Precision

        public void Serialization_Of_Dates_Has_Millisecond_Precision()
        {
            var obj1 = new GeneralDTO() { ADateTime = null };
            var obj2 = new GeneralDTO() { ADateTime = DateTime.Now };

            var obj1Bytes = BSONSerializer.Serialize(obj1);
            var obj2Bytes = BSONSerializer.Serialize(obj2);

            var hydratedObj1 = BSONSerializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BSONSerializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.AreEqual(null, hydratedObj1.ADateTime);

            //Mongo stores dates as long, therefore, we have to use double->long rounding.
            Assert.AreEqual((long)(obj2.ADateTime.Value - DateTime.MinValue).TotalMilliseconds,
                (long)(hydratedObj2.ADateTime.Value - DateTime.MinValue).TotalMilliseconds);
        }
开发者ID:jasona,项目名称:NoRM,代码行数:17,代码来源:BSONSerializerTest.cs

示例10: SerializationOfDatesHasMillisecondPrecision

        public void SerializationOfDatesHasMillisecondPrecision()
        {
            var obj1 = new GeneralDTO { ADateTime = null };
            var obj2 = new GeneralDTO { ADateTime = DateTime.Now };

            var obj1Bytes = BsonSerializer.Serialize(obj1);
            var obj2Bytes = BsonSerializer.Serialize(obj2);

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.Equal(null, hydratedObj1.ADateTime);

            //Mongo stores dates as long, therefore, we have to use double->long rounding.
            Assert.Equal((long)((obj2.ADateTime.Value.ToUniversalTime() - DateTime.MinValue)).TotalMilliseconds,
                (long)(hydratedObj2.ADateTime.Value - DateTime.MinValue).TotalMilliseconds);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:17,代码来源:BSONSerializerTest.cs

示例11: SerializesAndDeserializesAComplexObject

        public void SerializesAndDeserializesAComplexObject()
        {
            var obj1 = new GeneralDTO
            {
                Flags64 = Flags64.FlagOff,
                Flags32 = Flags32.FlagOn,
                Pi = 2d,
                AnInt = 3,
                Title = "telti",
                ABoolean = false,
                Strings = new[] { "a", "bb", "abc" },
                Bytes = new byte[] { 1, 2, 3 },
                AGuid = Guid.NewGuid(),
                ADateTime = new DateTime(2001, 4, 8, 10, 43, 23, 104),
                ARex = new Regex("it's over (9000)", RegexOptions.IgnoreCase)
            };
            var nested = new GeneralDTO { Pi = 43d, Title = "little", ARex = new Regex("^over (9000)$") };
            obj1.Nester = nested;
            var obj2 = new GeneralDTO();

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(BsonSerializer.Serialize(obj1));
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(BsonSerializer.Serialize(obj2));

            Assert.Equal(obj1.Pi, hydratedObj1.Pi);
            Assert.Equal(obj1.AnInt, hydratedObj1.AnInt);
            Assert.Equal(obj1.Title, hydratedObj1.Title);
            Assert.Equal(obj1.ABoolean, hydratedObj1.ABoolean);
            Assert.Equal(obj1.Bytes, hydratedObj1.Bytes);
            Assert.Equal(obj1.AGuid, hydratedObj1.AGuid);
            Assert.Equal(obj1.ADateTime.Value.ToUniversalTime().Ticks,
                hydratedObj1.ADateTime.Value.ToUniversalTime().Ticks);
            Assert.Equal(obj1.Strings, hydratedObj1.Strings);
            Assert.Equal(obj1.Flags32, hydratedObj1.Flags32);
            Assert.Equal(obj1.Flags64, hydratedObj1.Flags64);
            Assert.Equal(obj1.Nester.Title, hydratedObj1.Nester.Title);
            Assert.Equal(obj1.Nester.Pi, hydratedObj1.Nester.Pi);
            Assert.Equal(obj1.ARex.ToString(), hydratedObj1.ARex.ToString());
            Assert.Equal(obj1.ARex.Options, hydratedObj1.ARex.Options);

            Assert.Equal(obj2.Pi, hydratedObj2.Pi);
            Assert.Equal(obj2.AnInt, hydratedObj2.AnInt);
            Assert.Equal(obj2.Title, hydratedObj2.Title);
            Assert.Equal(obj2.ABoolean, hydratedObj2.ABoolean);
            Assert.Equal(obj2.Bytes, hydratedObj2.Bytes);
            Assert.Equal(obj2.AGuid, hydratedObj2.AGuid);
            Assert.Equal(obj2.ADateTime, hydratedObj2.ADateTime);
            Assert.Equal(obj2.Strings, hydratedObj2.Strings);
            Assert.Equal(obj2.Flags32, hydratedObj2.Flags32);
            Assert.Equal(obj2.Flags64, hydratedObj2.Flags64);
            Assert.Equal(obj2.Nester, hydratedObj2.Nester);
            Assert.Equal(obj2.ARex, hydratedObj2.ARex);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:52,代码来源:BSONSerializerTest.cs

示例12: SerializationSpeedTest

        public void SerializationSpeedTest()
        {
            for (var i = 0; i < 5; i++)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();

                for (var j = 0; j < 10000; j++)
                {
                    var obj1 = new GeneralDTO
                                   {
                                       Title = null,
                                       ABoolean = true,
                                       AGuid = Guid.NewGuid(),
                                       AnInt = 1,
                                       Pi = 3.14,
                                       Nester = new GeneralDTO { Title = "Bob", AnInt = 42 }
                                   };
                    var obj1Bytes = BsonSerializer.Serialize(obj1);
                    BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
                }
                stopWatch.Stop();
                Console.WriteLine(stopWatch.ElapsedMilliseconds);
            }
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:25,代码来源:BSONSerializerTest.cs

示例13: SerializationOfStringsAreNotLossy

        public void SerializationOfStringsAreNotLossy()
        {
            var obj1 = new GeneralDTO { Title = null };
            var obj2 = new GeneralDTO { Title = "Hello World" };

            var obj1Bytes = BsonSerializer.Serialize(obj1);
            var obj2Bytes = BsonSerializer.Serialize(obj2);

            var hydratedObj1 = BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
            var hydratedObj2 = BsonDeserializer.Deserialize<GeneralDTO>(obj2Bytes);

            Assert.Equal(null, hydratedObj1.Title);
            Assert.Equal(obj2.Title, hydratedObj2.Title);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:14,代码来源:BSONSerializerTest.cs

示例14: SerializationOfScopedCodeIsNotLossy

        public void SerializationOfScopedCodeIsNotLossy()
        {
            var obj1 = new GeneralDTO {Code = new ScopedCode {CodeString = "function(){return 'hello world!'}"}};
            var scope = new Expando();
            scope["$ns"] = "root";
            obj1.Code.Scope = scope;

            var obj2 = BsonDeserializer.Deserialize<GeneralDTO>(BsonSerializer.Serialize(obj1));

            Assert.Equal(obj1.Code.CodeString, obj2.Code.CodeString);
            Assert.Equal(((Expando)obj1.Code.Scope)["$ns"],((Expando)obj2.Code.Scope)["$ns"]);
        }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:12,代码来源:BSONSerializerTest.cs

示例15: RecursiveNestedTypesDontCauseInfiniteLoop

 public void RecursiveNestedTypesDontCauseInfiniteLoop()
 {
     var obj1 = new GeneralDTO { Title = "Hello World", Nester = new GeneralDTO { Title = "Bob", AnInt = 42 } };
     var obj1Bytes = BsonSerializer.Serialize(obj1);
     BsonDeserializer.Deserialize<GeneralDTO>(obj1Bytes);
 }
开发者ID:antoninwatr,项目名称:NoRM,代码行数:6,代码来源:BSONSerializerTest.cs


注:本文中的GeneralDTO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。