コード例 #1
0
        public void EnumTest1()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object3));

            Object3 o = (Object3)om.CreateInstance();

            om.SetValue(o, "Enum1", "1");
            om.SetValue(o, "Enum2", "2");
            om.SetValue(o, "Enum3", "30");
            om.SetValue(o, "Enum4", null);

            Assert.AreEqual(Enum1.Value1, o.Enum1);
            Assert.AreEqual(Enum1.Value2, o.Enum2);
            Assert.AreEqual(Enum1.Value3, o.Enum3);
            Assert.AreEqual(Enum1.Value4, o.Enum4);

            om.SetValue(o, "Enum3", "31");
            Assert.AreEqual(Enum1.Value3, o.Enum3);

            om.SetValue(o, "Enum3", "32");
            Assert.AreEqual(Enum1.Value3, o.Enum3);

            Assert.AreEqual("1", om.GetValue(o, "Enum1"));
            Assert.AreEqual("2", om.GetValue(o, "Enum2"));
            Assert.Contains(om.GetValue(o, "Enum3"), new[] { "30", "31", "32", "3" });
            Assert.IsNull(om.GetValue(o, "Enum4"));
        }
コード例 #2
0
        public void TestDerivedNull()
        {
            ObjectMapper   om = Map.GetObjectMapper(typeof(Object6Derived));
            Object6Derived o  = (Object6Derived)om.CreateInstance();

            om.SetValue(o, "String1", null);
            Console.WriteLine(o.String1);
        }
コード例 #3
0
        public void TestEnum3()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object3));

            Object3 o = (Object3)om.CreateInstance();

            om.SetValue(o, "Enum1", "55");

            Assert.AreEqual(Enum2.Value2, o.Enum1);

            Assert.AreEqual("2", om.GetValue(o, "Enum1"));
        }
コード例 #4
0
        public void Test1()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object1));

            Object1 o = (Object1)om.CreateInstance();

            om.SetValue(o, "mapname", 123);
            om.SetValue(o, "intfld", 234);

            Assert.AreEqual(123, o.Field1);
            Assert.AreEqual(234, o.Field2);
        }
コード例 #5
0
        public void BoolTest2()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object2));

            Object2 o = (Object2)om.CreateInstance();

            om.SetValue(o, "Bool1", "Y");
            om.SetValue(o, "Bool2", "Yes");

            Assert.AreEqual(true, o.Bool1);
            Assert.AreEqual(true, o.Bool2);

            Assert.AreEqual("Y", om.GetValue(o, "Bool1"));
            Assert.AreEqual("Y", om.GetValue(o, "Bool2"));
        }
コード例 #6
0
        public void DayOfWeekTest1()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object4));

            Object4 o = (Object4)om.CreateInstance();

            om.SetValue(o, "Dow1", "M");
            om.SetValue(o, "Dow2", "F");

            Assert.AreEqual(DayOfWeek.Monday, o.Dow1);
            Assert.AreEqual(DayOfWeek.Friday, o.Dow2);

            Assert.AreEqual("M", om.GetValue(o, "Dow1"));
            Assert.AreEqual("F", om.GetValue(o, "Dow2"));
        }
コード例 #7
0
        public void TestEnum1()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object1));

            Object1 o = (Object1)om.CreateInstance();

            om.SetValue(o, "Enum1", "55");
            om.SetValue(o, "Enum2", "66");

            Assert.AreEqual(Enum1.Value3, o.Enum1);
            Assert.AreEqual(Enum1.Value1, o.Enum2);

            Assert.AreEqual("3", om.GetValue(o, "Enum1"));
            Assert.AreEqual("1", om.GetValue(o, "Enum2"));
        }
コード例 #8
0
        public void TestPrimitive()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object5));

            Object5 o = (Object5)om.CreateInstance();

            om.SetValue(o, "Int1", null);
            om.SetValue(o, "Int2", null);
            om.SetValue(o, "Int3", null);

            Assert.AreEqual(0, o.Int1);
            Assert.AreEqual(0, o.Int2);
            Assert.AreEqual(int.MinValue, o.Int3);

            Assert.IsNotNull(om.GetValue(o, "Int1"));
            Assert.IsNull(om.GetValue(o, "Int2"));
            Assert.IsNull(om.GetValue(o, "Int3"));
        }
コード例 #9
0
        public void Test2()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object4));

            Object4 o = (Object4)om.CreateInstance();

            om.SetValue(o, "fld1", "Y");
            om.SetValue(o, "Object3.Object2.Field2", 123);
            om.SetValue(o, "fld2", "str");

            Assert.AreEqual(true, o.Object3.Object2.Field1);
            Assert.AreEqual(123, o.Object3.Object2.Field2);
            Assert.IsNull(o.Object3.Object4);

            Assert.AreEqual("Y", om.GetValue(o, "fld1"));
            Assert.AreEqual(123, om.GetValue(o, "Object3.Object2.Field2"));
            Assert.IsNull(om.GetValue(o, "fld2"));
        }
コード例 #10
0
        public void TestString2()
        {
            ObjectMapper om = Map.GetObjectMapper(typeof(Object2));

            Object2 o = (Object2)om.CreateInstance();

            om.SetValue(o, "Str1", null);
            om.SetValue(o, "Str2", null);
            om.SetValue(o, "Str3", null);
            om.SetValue(o, "Str4", null);

            Assert.AreEqual("", o.Str1);
            Assert.AreEqual("", o.Str2);
            Assert.AreEqual("(null)", o.Str3);
            Assert.IsNull(o.Str4);

            Assert.IsNotNull(om.GetValue(o, "Str1"));
            Assert.IsNull(om.GetValue(o, "Str2"));
            Assert.IsNull(om.GetValue(o, "Str3"));
            Assert.IsNull(om.GetValue(o, "Str4"));
        }
コード例 #11
0
ファイル: DataAccessor.cs プロジェクト: EIDSS/EIDSS6.1.0.45
        protected IEnumerable <T> ExecuteEnumerable <T>(DbManager db, Type objectType, bool disposeDbManager)
        {
            try
            {
                using (IDataReader rd = db.ExecuteReader())
                {
                    if (rd.Read())
                    {
                        ObjectMapper     dest   = MappingSchema.GetObjectMapper(objectType);
                        DataReaderMapper source = MappingSchema.CreateDataReaderMapper(rd);

                        InitContext ctx = new InitContext();

                        ctx.MappingSchema = MappingSchema;
                        ctx.ObjectMapper  = dest;
                        ctx.DataSource    = source;
                        ctx.SourceObject  = rd;

                        int[]          index   = MappingSchema.GetIndex(source, dest);
                        IValueMapper[] mappers = ctx.MappingSchema.GetValueMappers(source, dest, index);

                        do
                        {
                            T destObject = (T)dest.CreateInstance(ctx);

                            if (ctx.StopMapping)
                            {
                                yield return(destObject);
                            }

                            ISupportMapping smDest = destObject as ISupportMapping;

                            if (smDest != null)
                            {
                                smDest.BeginMapping(ctx);

                                if (ctx.StopMapping)
                                {
                                    yield return(destObject);
                                }
                            }

                            MappingSchema.MapInternal(source, rd, dest, destObject, index, mappers);

                            if (smDest != null)
                            {
                                smDest.EndMapping(ctx);
                            }

                            yield return(destObject);
                        } while (rd.Read());
                    }
                }
            }
            finally
            {
                if (disposeDbManager)
                {
                    db.Dispose();
                }
            }
        }