Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Added Culture to DittoConversionHandlerContext #216

Merged
merged 1 commit into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using Umbraco.Core.Models;

namespace Our.Umbraco.Ditto
Expand All @@ -13,6 +14,11 @@ public class DittoConversionHandlerContext
/// </summary>
public IPublishedContent Content { get; set; }

/// <summary>
/// Gets or sets the culture.
/// </summary>
public CultureInfo Culture { get; set; }

/// <summary>
/// Gets or sets the model object.
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions src/Our.Umbraco.Ditto/Extensions/PublishedContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public static class PublishedContentExtensions

// We have the instance object but haven't yet populated properties
// so fire the on converting event handlers
OnConverting(content, type, instance, onConverting);
OnConverting(content, type, culture, instance, onConverting);

// Process any non lazy properties next
foreach (var propertyInfo in properties.Where(x => !x.ShouldAttemptLazyLoad()))
Expand All @@ -401,7 +401,7 @@ public static class PublishedContentExtensions

// We have now finished populating the instance object so go ahead
// and fire the on converted event handlers
OnConverted(content, type, instance, onConverted);
OnConverted(content, type, culture, instance, onConverted);

return instance;
}
Expand Down Expand Up @@ -558,20 +558,23 @@ public static class PublishedContentExtensions
/// </summary>
/// <param name="content">The <see cref="IPublishedContent"/> to convert.</param>
/// <param name="type">The instance type.</param>
/// <param name="culture">The culture.</param>
/// <param name="instance">The instance to assign the value to.</param>
/// <param name="callback">
/// The <see cref="Action{ConversionHandlerContext}"/> to fire when converting.
/// </param>
private static void OnConverting(
IPublishedContent content,
Type type,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> callback)
{
OnConvert<DittoOnConvertingAttribute>(
DittoConversionHandlerType.OnConverting,
content,
type,
culture,
instance,
callback);
}
Expand All @@ -581,20 +584,23 @@ public static class PublishedContentExtensions
/// </summary>
/// <param name="content">The <see cref="IPublishedContent"/> to convert.</param>
/// <param name="type">The instance type.</param>
/// <param name="culture">The culture.</param>
/// <param name="instance">The instance to assign the value to.</param>
/// <param name="callback">
/// The <see cref="Action{ConversionHandlerContext}"/> to fire when converted.
/// </param>
private static void OnConverted(
IPublishedContent content,
Type type,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> callback)
{
OnConvert<DittoOnConvertedAttribute>(
DittoConversionHandlerType.OnConverted,
content,
type,
culture,
instance,
callback);
}
Expand All @@ -606,12 +612,14 @@ public static class PublishedContentExtensions
/// <param name="conversionType">Type of the conversion.</param>
/// <param name="content">The content.</param>
/// <param name="type">The type.</param>
/// <param name="culture">The culture.</param>
/// <param name="instance">The instance.</param>
/// <param name="callback">The callback.</param>
private static void OnConvert<TAttributeType>(
DittoConversionHandlerType conversionType,
IPublishedContent content,
Type type,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> callback)
where TAttributeType : Attribute
Expand All @@ -620,6 +628,7 @@ public static class PublishedContentExtensions
var conversionCtx = new DittoConversionHandlerContext
{
Content = content,
Culture = culture,
ModelType = type,
Model = instance
};
Expand Down