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

Commit

Permalink
Merge pull request #216 from leekelleher/devex/conversion-handler-con…
Browse files Browse the repository at this point in the history
…text-culture

Added Culture to DittoConversionHandlerContext
  • Loading branch information
leekelleher committed May 31, 2017
2 parents 97ff31a + 57b842d commit 175b300
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 175b300

Please sign in to comment.