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

Provide a nicer way to populate calculated properties #86

Merged
merged 12 commits into from
Jun 17, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.