Skip to content

Commit

Permalink
Fixes JasperFx#1369 - Updated GetProperties to also return private an…
Browse files Browse the repository at this point in the history
…d protected to allow eg. having private or protected setter for ID
  • Loading branch information
oskardudycz committed Nov 3, 2019
1 parent fbb159d commit addb2c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Marten/Schema/DocumentMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private static PropertyInfo[] GetProperties(Type type)
? new[] { type }
.Concat(type.GetInterfaces())
.SelectMany(i => i.GetProperties()).ToArray()
: type.GetProperties();
: type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic).OrderByDescending(x => x.DeclaringType == type).ToArray();
}

public void AddSubClass(Type subclassType, IEnumerable<MappedType> otherSubclassTypes, string alias)
Expand Down Expand Up @@ -730,7 +730,7 @@ public void Duplicate(Expression<Func<T, object>> expression, string pgType = nu
var visitor = new FindMembers();
visitor.Visit(expression);

var duplicateField = DuplicateField(visitor.Members.ToArray(), pgType, notNull:notNull);
var duplicateField = DuplicateField(visitor.Members.ToArray(), pgType, notNull: notNull);

if (dbType.HasValue)
duplicateField.DbType = dbType.Value;
Expand Down
11 changes: 5 additions & 6 deletions src/Marten/Schema/Identity/IdAssigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ namespace Marten.Schema.Identity
{
public class IdAssigner<TDoc, TId>: IdAssignment<TDoc>
{
private readonly IIdGenerator<TId> _generator;
public IIdGenerator<TId> Generator { get; }

private readonly Func<TDoc, TId> _getter;
private readonly Action<TDoc, TId> _setter;

public IdAssigner(MemberInfo member, IIdGeneration generation)
{
_generator = generation.Build<TId>();
Generator = generation.Build<TId>();
_getter = LambdaBuilder.Getter<TDoc, TId>(member);
_setter = LambdaBuilder.Setter<TDoc, TId>(member);
}

public IIdGenerator<TId> Generator => _generator;

public object Assign(ITenant tenant, TDoc document, out bool assigned)
{
var original = _getter != null ? _getter(document) : default(TId);
var original = _getter != null ? _getter(document) : default;

var id = _generator.Assign(tenant, original, out assigned);
var id = Generator.Assign(tenant, original, out assigned);

if (assigned)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Marten/Storage/Tenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ public IBulkLoader<T> BulkLoaderFor<T>()
{
var assignment = IdAssignmentFor<T>();

var mapping = MappingFor(typeof(T)).Root as DocumentMapping;

if (mapping == null)
if (!(MappingFor(typeof(T)).Root is DocumentMapping mapping))
throw new ArgumentOutOfRangeException("Marten cannot do bulk inserts on documents of type " + typeof(T).FullName);

return new BulkLoader<T>(_options.Serializer(), mapping, assignment);
Expand Down

0 comments on commit addb2c8

Please sign in to comment.