Refactoring the TypedModelBase and UmbracoTempaltePage for the TypedModel POC
This commit is contained in:
@@ -8,20 +8,13 @@ namespace Umbraco.Tests.PublishedContent.StronglyTypedModels
|
||||
{
|
||||
public abstract class TypedModelBase
|
||||
{
|
||||
private IPublishedContent _publishedContent;
|
||||
|
||||
protected TypedModelBase(){}
|
||||
private readonly IPublishedContent _publishedContent;
|
||||
|
||||
protected TypedModelBase(IPublishedContent publishedContent)
|
||||
{
|
||||
_publishedContent = publishedContent;
|
||||
}
|
||||
|
||||
internal void Add(IPublishedContent publishedContent)
|
||||
{
|
||||
_publishedContent = publishedContent;
|
||||
}
|
||||
|
||||
public readonly Func<MethodBase> Property = MethodBase.GetCurrentMethod;
|
||||
public static string DefaultString = default(string);
|
||||
public static int DefaultInteger = default(int);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent.StronglyTypedModels
|
||||
{
|
||||
public abstract class UmbracoTemplatePage<T> : UmbracoTemplatePage where T : TypedModelBase, new()
|
||||
public abstract class UmbracoTemplatePage<T> : UmbracoTemplatePage where T : TypedModelBase
|
||||
{
|
||||
protected override void InitializePage()
|
||||
{
|
||||
@@ -12,8 +13,11 @@ namespace Umbraco.Tests.PublishedContent.StronglyTypedModels
|
||||
if (Model != null)
|
||||
{
|
||||
//Map CurrentModel here
|
||||
TypedModel = new T();
|
||||
TypedModel.Add(Model.Content);
|
||||
var constructorInfo = typeof(T).GetConstructor(new []{typeof(IPublishedContent)});
|
||||
if (constructorInfo != null)
|
||||
{
|
||||
TypedModel = constructorInfo.Invoke(new object[]{Model.Content}) as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user