• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TypeMapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TransformedType_RequiredProperties_ReturnsRequiredProperties

 public void TransformedType_RequiredProperties_ReturnsRequiredProperties()
 {
     var mapper = new TypeMapper(new CritterPomonaConfiguration());
     var type = mapper.FromType(typeof(Planet));
     var requiredProperties = type.RequiredProperties.ToList();
     Assert.That(requiredProperties.All(x => x.IsRequiredForConstructor), Is.True);
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:7,代码来源:TypeSystemTests.cs


示例2: FromType_QueryResult_ReturnsQueryResultType

 public void FromType_QueryResult_ReturnsQueryResultType()
 {
     this.typeMapper = new TypeMapper(new SimplePomonaConfiguration());
     var type = TypeMapper.FromType(typeof(QueryResult<Critter>));
     Assert.That(type, Is.InstanceOf<QueryResultType>());
     Assert.That(type, Is.InstanceOf<QueryResultType<Critter>>());
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:7,代码来源:TypeMapperTests.cs


示例3: FindProperties

        /// <summary>
        /// 获取指定类型映射器的属性集合。
        /// </summary>
        /// <param name="mapper">类型映射器。</param>
        /// <param name="entity">类型映射器关联的对象实例,并将 <paramref name="entity"/> 转换成映射器的类型 。</param>
        /// <returns>映射属性的集合枚举。</returns>
        protected virtual IEnumerable<PropertyMapper> FindProperties(TypeMapper mapper, ref object entity)
        {
            IEnumerable<PropertyMapper> pms = mapper.Properties;
            var entityType = entity.GetType();
            if(entityType.IsAssignableFrom(mapper.Type)) return pms;

            var mapper2 = TypeMapper.Create(entityType);

            var query = from op in pms
                        join np in mapper2.Properties on op.Property.Name.ToLower() equals np.Name.ToLower()
                        select new { op, np };
            var entity2 = Activator.CreateInstance(mapper.Type, true);

            List<PropertyMapper> pms2 = new List<PropertyMapper>();
            foreach(var item in query)
            {
                pms2.Add(item.op);
                var value = item.np.GetValue(entity);
                if(!item.op.Property.PropertyType.IsAssignableFrom(item.np.Property.PropertyType))
                {
                    value = Convert.ChangeType(value, item.op.Property.PropertyType);
                }

                item.op.SetValue(entity2, value);
            }
            entity = entity2;
            return pms2;
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:34,代码来源:SqlFactory.cs


示例4: MapEntityType_should_not_map_invalid_structural_type

        public void MapEntityType_should_not_map_invalid_structural_type()
        {
            var model = new EdmModel().Initialize();
            var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model));

            Assert.Null(typeMapper.MapEntityType(typeof(string)));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:7,代码来源:TypeMapperTests.cs


示例5: Start

 public void Start()
 {
     var bootstrapper = new CritterBootstrapper();
     Repository = bootstrapper.Repository;
     TypeMapper = bootstrapper.TypeMapper;
     Host = new NancyHost(BaseUri, bootstrapper);
     Host.Start();
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:8,代码来源:CritterHost.cs


示例6: Start

 public void Start()
 {
     var bootstrapper = new CritterBootstrapper();
     this.Repository = bootstrapper.Repository;
     this.TypeMapper = bootstrapper.TypeMapper;
     host = new NancyHost(baseUri, bootstrapper);
     host.Start();
 }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:8,代码来源:CritterHost.cs


示例7: Setup

 public void Setup()
 {
     var fakeRepository = MockRepository.GenerateStub<IMapperRepository>();
     _mapper = new TypeMapper(fakeRepository);
     _dummyA = new DummyA { Name = "dummy A", Family = "family A", Age = 37 };
     _dummyB = new DummyB { Name = "dummy A", Family = "family A", Age = 37 };
     _dummyC = new DummyC { Name = "dummy A", Family = "family A", Address = null };
 }
开发者ID:haimtz,项目名称:Moshavit-Server,代码行数:8,代码来源:MapperGetMapTest.cs


示例8: GetUriFor_WithEntityWithSpaceInPath_EncodesUrlTheRightWay

 public void GetUriFor_WithEntityWithSpaceInPath_EncodesUrlTheRightWay()
 {
     var typeMapper = new TypeMapper(new CritterPomonaConfiguration());
     var uriResolver = new UriResolver(typeMapper,
         new DummyBaseUriProvider() { BaseUri = new Uri("http://whateva/") });
     var galaxy = new Galaxy() { Name = "this is it" };
     var url = uriResolver.GetUriFor(galaxy);
     Assert.That(url, Is.EqualTo("http://whateva/galaxies/this%20is%20it"));
 }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:9,代码来源:UriResolverTests.cs


示例9: CanMapSimpleNullableTypes

        public void CanMapSimpleNullableTypes(Type type, string expectedParamType, string expectedFormat = "")
        {
            var mapper = new TypeMapper();
            var inputParam = new InputParameter { Type = type };
            var param = mapper.Map(inputParam);

            Assert.AreEqual(expectedParamType, param.type);
            Assert.AreEqual(expectedFormat, param.format);

            Assert.IsEmpty(mapper.Models);
        }
开发者ID:huoxudong125,项目名称:OpenRastaSwagger,代码行数:11,代码来源:TypeMapperFixture.cs


示例10: CanMapEnumerableIntegerTypes

        public void CanMapEnumerableIntegerTypes(Type collectionType)
        {
            var mapper = new TypeMapper();

            var param = mapper.Register(collectionType);

            Assert.AreEqual("array", param.Type);
            Assert.AreEqual("integer", param.Items.Type);

            Assert.IsEmpty(mapper.Models);
        }
开发者ID:huoxudong125,项目名称:OpenRastaSwagger,代码行数:11,代码来源:TypeMapperFixture.cs


示例11: MapComplexType_should_not_map_ignored_type

        public void MapComplexType_should_not_map_ignored_type()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var mockModelConfiguration = new Mock<ModelConfiguration>();
            var typeMapper = new TypeMapper(new MappingContext(mockModelConfiguration.Object, new ConventionsConfiguration(), model));
            mockModelConfiguration.Setup(m => m.IsIgnoredType(typeof(AType1))).Returns(true);

            var complexType = typeMapper.MapComplexType(typeof(AType1));

            Assert.Null(complexType);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:TypeMapperTests.cs


示例12: ClientLibGenerator

 public ClientLibGenerator(TypeMapper typeMapper)
 {
     if (typeMapper == null)
         throw new ArgumentNullException("typeMapper");
     this.typeMapper = typeMapper;
     this.allowedReferencedAssemblies = new[]
     {
         /*mscorlib*/typeof(string).Assembly, typeof(IPomonaClient).Assembly, /*System.Core*/
         typeof(Func<>).Assembly, /*System*/ typeof(Uri).Assembly
     };
     PomonaClientEmbeddingEnabled = true;
 }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:12,代码来源:ClientLibGenerator.cs


示例13: MapEntityType_should_not_map_ignored_type

        public void MapEntityType_should_not_map_ignored_type()
        {
            var model = new EdmModel().Initialize();
            var mockModelConfiguration = new Mock<ModelConfiguration>();
            var typeMapper = new TypeMapper(new MappingContext(mockModelConfiguration.Object, new ConventionsConfiguration(), model));
            var mockType = new MockType("Foo");
            mockModelConfiguration.Setup(m => m.IsIgnoredType(mockType)).Returns(true);

            var entityType = typeMapper.MapEntityType(mockType);

            Assert.Null(entityType);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:12,代码来源:TypeMapperTests.cs


示例14: ToFactory

 public Factory ToFactory(IEnumerable<Column> columns, TypeMapper typeMapper)
 {
   if (columns.Count() != _attributes.Count())
   {
     throw new InvalidOperationException("Did not get equal number of Columns and Attributes");
   }
   var readers = columns.Zip<Column, Attribute, Func<object[], object>>(_attributes, (column, attribute) => {
     var mapper = typeMapper.MappingFor(column, attribute);
     return (row) => mapper(column.Read(row));
   });
   return new Factory(_info, readers.ToArray());
 }
开发者ID:machine,项目名称:machine.sqlmap,代码行数:12,代码来源:TypeConstructor.cs


示例15: HandlerMethod

 public HandlerMethod(MethodInfo methodInfo, TypeMapper typeMapper)
 {
     if (methodInfo == null)
         throw new ArgumentNullException(nameof(methodInfo));
     if (typeMapper == null)
         throw new ArgumentNullException(nameof(typeMapper));
     MethodInfo = methodInfo;
     TypeMapper = typeMapper;
     this.parameters =
         new Lazy<IList<HandlerParameter>>(
             () => methodInfo.GetParameters().Select(x => new HandlerParameter(x, this)).ToList());
     this.parameterTypes = new Lazy<IList<Type>>(() => Parameters.MapList(x => x.Type));
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:13,代码来源:HandlerMethod.cs


示例16: MapEntityType_should_not_bring_in_base_class_by_default

        public void MapEntityType_should_not_bring_in_base_class_by_default()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model));

            var entityType = typeMapper.MapEntityType(typeof(AType3));

            Assert.NotNull(entityType);
            Assert.Null(entityType.BaseType);
            Assert.Equal(1, model.EntityTypes.Count());
            Assert.Equal(1, model.Containers.Single().EntitySets.Count);
            Assert.Equal("AType3", model.GetEntitySet(entityType).Name);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:13,代码来源:TypeMapperTests.cs


示例17: HandlesCircularReferences__ObjectReferencesSelfDirectly

        public void HandlesCircularReferences__ObjectReferencesSelfDirectly()
        {
            var n = new LinkedListNode { Id = 13 };
            n.Next = n;
            n.Previous = n;

            var tm = new TypeMapper();

            var clone = tm.DeepClone<LinkedListNode>(n);

            Assert.AreEqual(13, clone.Id);
            Assert.AreSame(n, n.Next);
            Assert.AreSame(n, n.Previous);
        }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:14,代码来源:TypeMapper.DeepClone.tests.cs


示例18: MapEntityType_should_not_bring_in_base_class_by_default

        public void MapEntityType_should_not_bring_in_base_class_by_default()
        {
            var model = new EdmModel().Initialize();
            var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model));
            var mockType = new MockType("Bar").BaseType(new MockType("Foo"));

            var entityType = typeMapper.MapEntityType(mockType);

            Assert.NotNull(entityType);
            Assert.Null(entityType.BaseType);
            Assert.Equal(1, model.Namespaces.Single().EntityTypes.Count);
            Assert.Equal(1, model.Containers.Single().EntitySets.Count);
            Assert.Equal("Bar", model.GetEntitySet(entityType).Name);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:14,代码来源:TypeMapperTests.cs


示例19: CanCloneAnObject

        public void CanCloneAnObject()
        {
            var st = new SimpleType();
            st.EnumProperty = DayOfWeek.Friday;
            st.IntegerProperty = 13;
            st.StringProperty = "some string";

            var tm = new TypeMapper();

            var clone = tm.DeepClone<SimpleType>(st);

            Assert.AreEqual(st.EnumProperty, clone.EnumProperty);
            Assert.AreEqual(st.IntegerProperty, clone.IntegerProperty);
            Assert.AreEqual(st.StringProperty, clone.StringProperty);
        }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:15,代码来源:TypeMapper.DeepClone.tests.cs


示例20: MapEntityType_should_bring_in_derived_types_from_the_same_assembly

        public void MapEntityType_should_bring_in_derived_types_from_the_same_assembly()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model));

            var mockType1 = new MockType("Foo");
            var mockType2 = new MockType("Bar").BaseType(mockType1);

            new MockAssembly(mockType1, mockType2);

            typeMapper.MapEntityType(mockType1);

            Assert.Equal(2, model.EntityTypes.Count());
            Assert.Equal(1, model.Containers.Single().EntitySets.Count);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:15,代码来源:TypeMapperTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TypeMemberModifiers类代码示例发布时间:2022-05-24
下一篇:
C# TypeMap类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap