From b1037d1936b636572bfe2ac85f486ae98fff7ffa Mon Sep 17 00:00:00 2001 From: Robert Foster Date: Sun, 30 Mar 2014 19:07:35 +1100 Subject: [PATCH] Added a TagMapper class to resolve ITag back to TagDto. --- .../Persistence/Mappers/TagMapper.cs | 44 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + 2 files changed, 45 insertions(+) create mode 100644 src/Umbraco.Core/Persistence/Mappers/TagMapper.cs diff --git a/src/Umbraco.Core/Persistence/Mappers/TagMapper.cs b/src/Umbraco.Core/Persistence/Mappers/TagMapper.cs new file mode 100644 index 0000000000..672a433b12 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Mappers/TagMapper.cs @@ -0,0 +1,44 @@ +using System.Collections.Concurrent; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Rdbms; + +namespace Umbraco.Core.Persistence.Mappers +{ + /// + /// Represents a to DTO mapper used to translate the properties of the public api + /// implementation to that of the database's DTO as sql: [tableName].[columnName]. + /// + [MapperFor(typeof(Tag))] + [MapperFor(typeof(ITag))] + public sealed class TagMapper : BaseMapper + { + private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary(); + + //NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it + // otherwise that would fail because there is no public constructor. + public TagMapper() + { + BuildMap(); + } + + #region Overrides of BaseMapper + + internal override ConcurrentDictionary PropertyInfoCache + { + get { return PropertyInfoCacheInstance; } + } + + internal override void BuildMap() + { + if (PropertyInfoCache.IsEmpty) + { + CacheMap(src => src.Id, dto => dto.Id); + CacheMap(src => src.Text, dto => dto.Tag); + CacheMap(src => src.Group, dto => dto.Group); + //CacheMap(src => src., dto => dto.ParentId); // Doesn't seem to be enabled - RJF + } + } + + #endregion + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 264612e738..d85391a0cd 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -364,6 +364,7 @@ +