Skip to content

Commit

Permalink
Add ResolveKeyProperty extension methods for backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
henkmollema committed Oct 19, 2018
1 parent e3a7439 commit b48561f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Dommel/DommelMapper.IKeyPropertyResolver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using static Dommel.DommelMapper;

namespace Dommel
{
Expand Down Expand Up @@ -27,4 +29,29 @@ public interface IKeyPropertyResolver
PropertyInfo[] ResolveKeyProperties(Type type, out bool isIdentity);
}
}

/// <summary>
/// Extensions for <see cref="IKeyPropertyResolver"/>.
/// </summary>
public static class KeyPropertyResolverExtensions
{
/// <summary>
/// Resolves the single key property for the specified type.
/// </summary>
/// <param name="keyPropertyResolver">The <see cref="IKeyPropertyResolver"/>.</param>
/// <param name="type">The type to resolve the key property for.</param>
/// <returns>A <see cref="PropertyInfo"/> instance of the key property of <paramref name="type"/>.</returns>
public static PropertyInfo ResolveKeyProperty(this IKeyPropertyResolver keyPropertyResolver, Type type)
=> keyPropertyResolver.ResolveKeyProperties(type).FirstOrDefault();

/// <summary>
/// Resolves the single key property for the specified type.
/// </summary>
/// <param name="keyPropertyResolver">The <see cref="IKeyPropertyResolver"/>.</param>
/// <param name="type">The type to resolve the key property for.</param>
/// <param name="isIdentity">Indicates whether the key properties are identity properties.</param>
/// <returns>A <see cref="PropertyInfo"/> instance of the key property of <paramref name="type"/>.</returns>
public static PropertyInfo ResolveKeyProperty(this IKeyPropertyResolver keyPropertyResolver, Type type, out bool isIdentity) =>
keyPropertyResolver.ResolveKeyProperties(type, out isIdentity).FirstOrDefault();
}
}

0 comments on commit b48561f

Please sign in to comment.