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 #86 from leekelleher/feature/on-converted-attribute
Browse files Browse the repository at this point in the history
Provide a nicer way to populate calculated properties
  • Loading branch information
mattbrailsford committed Jun 17, 2015
2 parents 537f888 + d1c3965 commit 5abfdc7
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Our.Umbraco.Ditto.ComponentModel.ConversionHandlers;

namespace Our.Umbraco.Ditto.Attributes
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class DittoConversionHandlerAttribute : Attribute
{
public Type HandlerType { get; private set; }

public DittoConversionHandlerAttribute(Type handlerType)
{
if (!typeof(DittoConversionHandler).IsAssignableFrom(handlerType))
throw new ArgumentException("Handler type must inherit from DittoConversionHandler", "handlerType");

HandlerType = handlerType;
}
}
}
8 changes: 8 additions & 0 deletions src/Our.Umbraco.Ditto/Attributes/DittoOnConvertedAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Our.Umbraco.Ditto.Attributes
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class DittoOnConvertedAttribute : Attribute
{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Our.Umbraco.Ditto.Attributes
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class DittoOnConvertingAttribute : Attribute
{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Umbraco.Core.Models;

namespace Our.Umbraco.Ditto.ComponentModel.ConversionHandlers
{
public abstract class DittoConversionHandler
{
public IPublishedContent Content { get; private set; }
public Type ModelType { get; private set; }
public object Model { get; private set; }

protected DittoConversionHandler(DittoConversionHandlerContext ctx)
{
Content = ctx.Content;
ModelType = ctx.ModelType;
Model = ctx.Model;
}

public virtual void OnConverting()
{ }

public virtual void OnConverted()
{ }
}

public abstract class DittoConversionHandler<TConvertedType> : DittoConversionHandler
where TConvertedType : class
{
public new TConvertedType Model { get; private set; }

protected DittoConversionHandler(DittoConversionHandlerContext ctx)
: base(ctx)
{
Model = ctx.Model as TConvertedType;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Umbraco.Core.Models;

namespace Our.Umbraco.Ditto.ComponentModel
{
/// <summary>
/// Provides context for conversion events.
/// </summary>
public class DittoConversionHandlerContext
{
/// <summary>
/// Gets or sets the content.
/// </summary>
public IPublishedContent Content { get; set; }

/// <summary>
/// Gets or sets the model object.
/// </summary>
public object Model { get; set; }

/// <summary>
/// Gets or sets the model type.
/// </summary>
public Type ModelType { get; set; }
}
}
27 changes: 0 additions & 27 deletions src/Our.Umbraco.Ditto/EventArgs/ConvertedTypeEventArgs.cs

This file was deleted.

17 changes: 0 additions & 17 deletions src/Our.Umbraco.Ditto/EventArgs/ConvertingTypeEventArgs.cs

This file was deleted.

48 changes: 0 additions & 48 deletions src/Our.Umbraco.Ditto/EventArgs/DittoEventHandlers.cs

This file was deleted.

0 comments on commit 5abfdc7

Please sign in to comment.