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


C# Mapping.PropertyMap方法代码示例

本文整理汇总了C#中Mapping.PropertyMap方法的典型用法代码示例。如果您正苦于以下问题:C# Mapping.PropertyMap方法的具体用法?C# Mapping.PropertyMap怎么用?C# Mapping.PropertyMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mapping的用法示例。


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

示例1: GenerateToObject_WhenCalledWithVariableTableTypeAndPropertyMap_UsesPropertyMap

        public void GenerateToObject_WhenCalledWithVariableTableTypeAndPropertyMap_UsesPropertyMap()
        {
            IMapping mapping = new Mapping();

            Func<IDataRecord, Type> variableTableType = dataRecord => typeof( StringScore );

            mapping.VariableTableType<BaseScore>( variableTableType );
            Func<IDataRecord, string> action = dataRecord => "The Score Is: " + dataRecord.GetString( 2 );
            mapping.PropertyMap<StringScore, String>( x => x.ValueString, action );

            mapping.Table<BaseScore>( 0 );

            var classMapResult = new ClassMapResult
            {
                Mappings = (Mapping)mapping
            };

            var mockDataReader = new MockDataReader();

            var scores = mockDataReader.AddTable( "Id", "ResultId", "ValueString", "ResultType" );

            mockDataReader.AddRow( scores, 1, 1, "10", 2 );

            var func = MappingGenerator.Generate<List<BaseScore>>( new MockDataReader(), classMapResult );

            var dictionary = new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>();

            var result = func( mockDataReader, new Dictionary<MappingEnum, object>
            {
                {
                    MappingEnum.VariableTableType, new Dictionary<Type, object>
                    {
                        { typeof( BaseScore ), variableTableType }
                    }
                },
                {
                    MappingEnum.PropertyMap, new Dictionary<PropertyInfo, PropertyMap>
                    {
                        {
                            typeof( StringScore ).GetProperty( "ValueString" ), new PropertyMap( action )
                        }
                    }
                }
            }, dictionary );

            Assert.AreEqual( 1, result[ 0 ].Id );

            Assert.IsInstanceOf<StringScore>( result[ 0 ] );

            Assert.AreEqual( "The Score Is: 10", ( result[ 0 ] as StringScore ).ValueString );
        }
开发者ID:jrote1,项目名称:SqlObjectHydrator,代码行数:51,代码来源:MappingGeneratorTests.cs

示例2: GenerateToObject_WhenCalledWithPropertyMapColumnName_ReturnsCorrectData

        public void GenerateToObject_WhenCalledWithPropertyMapColumnName_ReturnsCorrectData()
        {
            IMapping mapping = new Mapping();

            mapping.Table<TestClass>( 0 );
            mapping.PropertyMap<TestClass,string>( x => x.Name1, "Name" );

            var classMapResult = new ClassMapResult
            {
                Mappings = (Mapping)mapping
            };

            var mockDataReader = new MockDataReader();

            var scores = mockDataReader.AddTable( "Name" );

            string expectedName = "The name";
            mockDataReader.AddRow( scores, expectedName );

            var func = MappingGenerator.Generate<List<TestClass>>( new MockDataReader(), classMapResult );

            var dictionary = new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>();

            var result = func( mockDataReader, new Dictionary<MappingEnum, object>
            {
                {
                    MappingEnum.PropertyMap, new Dictionary<PropertyInfo, PropertyMap>
                    {
                        {
                            typeof( TestClass ).GetProperty( "Name1" ), new PropertyMap( "Name" )
                        }
                    }
                }
            }, dictionary );

            Assert.AreEqual( expectedName, result[ 0 ].Name1 );
        }
开发者ID:jrote1,项目名称:SqlObjectHydrator,代码行数:37,代码来源:MappingGeneratorTests.cs


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