using System;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Web.PublishedCache
{
///
/// A published property base that uses a raw object value
///
internal class RawValueProperty : PublishedPropertyBase
{
private readonly object _dbVal; //the value in the db
private readonly Lazy _sourceValue;
private readonly Lazy _objectValue;
private readonly Lazy _xpathValue;
///
/// Gets the raw value of the property.
///
public override object DataValue { get { return _dbVal; } }
public override bool HasValue
{
get { return _dbVal != null && _dbVal.ToString().Trim().Length > 0; }
}
public override object Value { get { return _objectValue.Value; } }
public override object XPathValue { get { return _xpathValue.Value; } }
public RawValueProperty(PublishedPropertyType propertyType, object propertyData)
: this(propertyType)
{
if (propertyData == null)
throw new ArgumentNullException("propertyData");
_dbVal = propertyData;
}
public RawValueProperty(PublishedPropertyType propertyType)
: base(propertyType)
{
_dbVal = null;
_sourceValue = new Lazy(() => PropertyType.ConvertDataToSource(_dbVal, false));
_objectValue = new Lazy(() => PropertyType.ConvertSourceToObject(_sourceValue.Value, false));
_xpathValue = new Lazy(() => PropertyType.ConvertSourceToXPath(_sourceValue.Value, false));
}
}
}