本文整理汇总了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();
}
示例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" });
}
示例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);
}
示例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);
}
}
示例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);
}
}
}