This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from leekelleher/feature/on-converted-attribute
Provide a nicer way to populate calculated properties
- Loading branch information
Showing
14 changed files
with
335 additions
and
171 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/Our.Umbraco.Ditto/Attributes/DittoConversionHandlerAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
8
src/Our.Umbraco.Ditto/Attributes/DittoOnConvertedAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Our.Umbraco.Ditto/Attributes/DittoOnConvertingAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ } | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Our.Umbraco.Ditto/ComponentModel/ConversionHandlers/DittoConversionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Our.Umbraco.Ditto/ComponentModel/DittoConversionHandlerContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/Our.Umbraco.Ditto/EventArgs/ConvertingTypeEventArgs.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.