Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Add overload of GetValue to set default value #81

Open
bjarnef opened this issue Oct 19, 2017 · 0 comments
Open

Add overload of GetValue to set default value #81

bjarnef opened this issue Oct 19, 2017 · 0 comments

Comments

@bjarnef
Copy link
Contributor

bjarnef commented Oct 19, 2017

It would be nice to have an overload of GetValue<T>()

public T GetValue<T>(string propertyAlias)
{
var property = GetProperty(propertyAlias);
if (IsEmptyProperty(property))
{
return default(T);
}
if (property.Value is long)
{
int newValue;
if (Int32.TryParse(property.Value.ToString(), out newValue)) {
property.Value = newValue;
}
}
return property.GetValue<T>();
}

var text = item.GetValue<string>("text", "No description")
var numberOfNewsItems = item.GetValue<int>("numberOfNewsItems", 3)

so you can set default value, like in Umbraco core:
https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Web/PublishedContentPropertyExtension.cs#L19-L22

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant