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


C# BsonClassMap.MapConstructor方法代码示例

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


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

示例1: Apply_should_do_nothing_when_constructor_parameter_name_does_not_match_any_property_or_field

        public void Apply_should_do_nothing_when_constructor_parameter_name_does_not_match_any_property_or_field()
        {
            var subject = new NamedParameterCreatorMapConvention();
            var classMap = new BsonClassMap<C>();
            var constructorInfo = typeof(C).GetTypeInfo().GetConstructor(new[] { typeof(int) });
            var creatorMap = classMap.MapConstructor(constructorInfo);
            creatorMap.Arguments.Should().BeNull();

            subject.Apply(creatorMap);

            creatorMap.Arguments.Should().BeNull();
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:NamedParameterCreatorMapConventionTests.cs

示例2: Apply_should_set_arguments_when_constructor_parameter_names_match_a_field

        public void Apply_should_set_arguments_when_constructor_parameter_names_match_a_field()
        {
            var subject = new NamedParameterCreatorMapConvention();
            var classMap = new BsonClassMap<C>();
            var constructorInfo = typeof(C).GetTypeInfo().GetConstructor(new[] { typeof(long) });
            var creatorMap = classMap.MapConstructor(constructorInfo);
            creatorMap.Arguments.Should().BeNull();

            subject.Apply(creatorMap);

            creatorMap.Arguments.Cast<FieldInfo>().Select(p => p.Name).Should().Equal(new[] { "F" });
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:NamedParameterCreatorMapConventionTests.cs

示例3: Apply_should_do_nothing_when_creator_map_already_has_arguments_configured

        public void Apply_should_do_nothing_when_creator_map_already_has_arguments_configured()
        {
            var subject = new NamedParameterCreatorMapConvention();
            var classMap = new BsonClassMap<C>();
            var constructorInfo = typeof(C).GetTypeInfo().GetConstructor(new[] { typeof(int) });
            var creatorMap = classMap.MapConstructor(constructorInfo, "Y");
            var originalArguments = creatorMap.Arguments;

            subject.Apply(creatorMap);

            creatorMap.Arguments.Should().BeSameAs(originalArguments);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:NamedParameterCreatorMapConventionTests.cs

示例4: Apply

        /// <inheritdoc />
        public void Apply(BsonClassMap classMap)
        {
            var typeInfo = classMap.ClassType.GetTypeInfo();
            if (typeInfo.IsAbstract)
            {
                return;
            }

            if (typeInfo.GetConstructor(Type.EmptyTypes) != null)
            {
                return;
            }

            foreach (var ctor in typeInfo.GetConstructors())
            {
                var parameters = ctor.GetParameters();
                var properties = typeInfo.GetProperties();
                if (parameters.Length != properties.Length)
                {
                    continue;
                }

                var matches = parameters
                    .GroupJoin(properties,
                        parameter => parameter.Name,
                        property => property.Name,
                        (parameter, props) => new { parameter, properties = props },
                        StringComparer.OrdinalIgnoreCase);

                if (matches.Any(m => m.properties.Count() != 1 || m.properties.ElementAt(0).CanWrite))
                {
                    continue;
                }

                classMap.MapConstructor(ctor);
            }
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:38,代码来源:ImmutableTypeClassMapConvention.cs

示例5: OptInMembersWithBsonCreatorMapModifierAttribute

            private void OptInMembersWithBsonCreatorMapModifierAttribute(BsonClassMap classMap)
            {
                // let other constructors opt-in if they have any IBsonCreatorMapAttribute attributes
                foreach (var constructorInfo in classMap.ClassType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                {
                    var hasAttribute = constructorInfo.GetCustomAttributes(typeof(IBsonCreatorMapAttribute), false).Any();
                    if (hasAttribute)
                    {
                        classMap.MapConstructor(constructorInfo);
                    }
                }

                // let other static factory methods opt-in if they have any IBsonCreatorMapAttribute attributes
                foreach (var methodInfo in classMap.ClassType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                {
                    var hasAttribute = methodInfo.GetCustomAttributes(typeof(IBsonCreatorMapAttribute), false).Any();
                    if (hasAttribute)
                    {
                        classMap.MapFactoryMethod(methodInfo);
                    }
                }
            }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:22,代码来源:AttributeConventionPack.cs


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