Reintroduce IPublishedContentProperty

This commit is contained in:
Stephan
2014-04-29 09:44:15 +02:00
parent b98fbbc75d
commit d33cc29f98
5 changed files with 66 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Umbraco.Core.Models;
using System.Web;
@@ -43,5 +44,13 @@ namespace Umbraco.Core.Dynamics
var value = Value;
return value == null ? string.Empty : value.ToString();
}
// see notes in IPublishedProperty
[Obsolete("Use PropertyTypeAlias.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Alias { get { return PropertyTypeAlias; } }
[Obsolete]
[EditorBrowsable(EditorBrowsableState.Never)]
public Guid Version { get { return Guid.Empty; } }
}
}

View File

@@ -1,9 +1,12 @@
using System;
using System.ComponentModel;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a property of an <c>IPublishedContent</c>.
/// </summary>
public interface IPublishedProperty
public interface IPublishedProperty : IPublishedContentProperty
{
/// <summary>
/// Gets the alias of the property.
@@ -45,7 +48,7 @@ namespace Umbraco.Core.Models
/// <para>It can be null, or any type of CLR object.</para>
/// <para>It has been fully prepared and processed by the appropriate converter.</para>
/// </remarks>
object Value { get; }
new object Value { get; }
/// <summary>
/// Gets the XPath value of the property.
@@ -57,4 +60,14 @@ namespace Umbraco.Core.Models
/// </remarks>
object XPathValue { get; }
}
// had to re-introduce that one for backward-compatibility reasons
[Obsolete("Use IPublishedProperty.", false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IPublishedContentProperty
{
string Alias { get; }
object Value { get; }
Guid Version { get; }
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
namespace Umbraco.Core.Models.PublishedContent
{
@@ -27,5 +28,13 @@ namespace Umbraco.Core.Models.PublishedContent
public abstract object DataValue { get; }
public abstract object Value { get; }
public abstract object XPathValue { get; }
// see notes in IPublishedProperty
[Obsolete("Use PropertyTypeAlias.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Alias { get { return PropertyTypeAlias; } }
[Obsolete]
[EditorBrowsable(EditorBrowsableState.Never)]
public Guid Version { get { return Guid.Empty; } }
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -231,6 +232,14 @@ namespace Umbraco.Tests.PublishedContent
public object Value { get; set; }
public bool HasValue { get; set; }
public object XPathValue { get; set; }
// see notes in IPublishedProperty
[Obsolete("Use PropertyTypeAlias.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Alias { get { return PropertyTypeAlias; } }
[Obsolete]
[EditorBrowsable(EditorBrowsableState.Never)]
public Guid Version { get { return Guid.Empty; } }
}
[PublishedContentModel("ContentType2")]

View File

@@ -1,4 +1,5 @@
using Umbraco.Core;
using System;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.PropertyEditors;
@@ -57,5 +58,27 @@ namespace Umbraco.Web
}
#endregion
#region IPublishedContentProperty.GetValue<T>
// see notes in IPublishedProperty
public static T GetValue<T>(this IPublishedContentProperty property)
{
var property2 = property as IPublishedProperty;
if (property2 == null) // should never happen
throw new ArgumentException("Not an IPublishedProperty.", "property");
return property2.GetValue(false, default(T));
}
public static T GetValue<T>(this IPublishedContentProperty property, T defaultValue)
{
var property2 = property as IPublishedProperty;
if (property2 == null) // should never happen
throw new ArgumentException("Not an IPublishedProperty.", "property");
return property2.GetValue(true, defaultValue);
}
#endregion
}
}