using System.Reflection; using Dapper; namespace Galaeth.DAL.Infrastructure; /// /// Fallback type mapper. /// public class FallbackTypeMapper : SqlMapper.ITypeMap { private readonly IEnumerable _mappers; /// /// Initializes a new instance of the class. /// /// Collection of . public FallbackTypeMapper(IEnumerable mappers) { _mappers = mappers; } /// /// Find constructor. /// /// Collection of names. /// Collection of types. /// Instance of . public ConstructorInfo FindConstructor(string[] names, Type[] types) { foreach (var mapper in _mappers) { try { var result = mapper.FindConstructor(names, types); if (result != null) { return result; } } catch { // Do nothing } } return null; } /// /// Find explicit constructor. /// /// Instance of . public ConstructorInfo FindExplicitConstructor() { return null; } /// /// Get constructor paramter map. /// /// Instance of . /// Column name. /// Instance of . public SqlMapper.IMemberMap GetConstructorParameter(ConstructorInfo constructor, string columnName) { foreach (var mapper in _mappers) { try { var result = mapper.GetConstructorParameter(constructor, columnName); if (result != null) { return result; } } catch { // Do nothing. } } return null; } /// /// Get member. /// /// Column name. /// Instance of . public SqlMapper.IMemberMap GetMember(string columnName) { foreach (var mapper in _mappers) { try { var result = mapper.GetMember(columnName); if (result != null) { return result; } } catch { // Do nothing. } } return null; } }