Updated to return nulls as opposed to the ex being caught with a meaningful message

This commit is contained in:
Warren Buckley
2017-08-09 10:23:55 +01:00
parent 8b962cff0c
commit b60c700e05

View File

@@ -264,17 +264,7 @@ namespace Umbraco.Core.Models
/// <returns><see cref="Property"/> Value as an <see cref="object"/></returns>
public virtual object GetValue(string propertyTypeAlias)
{
try
{
return Properties[propertyTypeAlias].Value;
}
catch (KeyNotFoundException ex)
{
var message = string.Format("Cannot find the property with alias '{0}' for the node named '{1}' with id '{2} that uses the document type alias '{3}'",
propertyTypeAlias, this.Name, this.Id, this.ContentTypeBase.Alias);
throw new Exception(message, ex);
}
return Properties.Contains(propertyTypeAlias) ? Properties[propertyTypeAlias].Value : null;
}
/// <summary>
@@ -285,18 +275,13 @@ namespace Umbraco.Core.Models
/// <returns><see cref="Property"/> Value as a <see cref="TPassType"/></returns>
public virtual TPassType GetValue<TPassType>(string propertyTypeAlias)
{
try
if (Properties.Contains(propertyTypeAlias) == false)
{
var convertAttempt = Properties[propertyTypeAlias].Value.TryConvertTo<TPassType>();
return convertAttempt.Success ? convertAttempt.Result : default(TPassType);
}
catch (KeyNotFoundException ex)
{
var message = string.Format("Cannot find the property with alias '{0}' for the node named '{1}' with id '{2} that uses the document type alias '{3}'",
propertyTypeAlias, this.Name, this.Id, this.ContentTypeBase.Alias);
return default(TPassType);
}
throw new Exception(message, ex);
}
var convertAttempt = Properties[propertyTypeAlias].Value.TryConvertTo<TPassType>();
return convertAttempt.Success ? convertAttempt.Result : default(TPassType);
}
/// <summary>