AI OnAI Off
Hm why can't I edit the first post? Anyway... i ment "writing" not "wringing", haha
Maybe something like this?
foreach (var expression in expressions)
{
var compiled = expression.Compile();
TPropertyValue value = compiled.Invoke(pageData);
if (value != null && !string.IsNullOrEmpty(value.ToString()))
return value.ToString();
}
Although, you could change the property to accept a list of strings or objects, so that you could pass in other properties as well, that is part of your view model and not necessarily in the pagedata object.
Something like this, perhaps?
private static string FirstNotEmpty(params string[] sources)
{
foreach (var source in sources)
{
if (!string.IsNullOrWhiteSpace(source))
{
return source;
}
}
return string.Empty;
}
Im wringing an extension that takes in a list of expression and a T value of PageData. The idea is that you should be able to specify a list of properties and the code will take the first property of that list if its set and return its string value with stripped html and shortened text.
At the moment the method looks like this:
This code work well for properties on the page. I could use this extension like this: @Model.CurrentPage.GetPuffText(100, string.Empty, x => x.Intro, x => x.MainBody);
But if the property i want to reach is within a local block on the page and the call would look like this: @(Model.CurrentPage.GetPuffText(100, string.Empty, x=> x.Listing.ListingText, x => x.MainContent.MainBody))
Then i wouldn't find anything. I would instead have to add x => x.MainContent as a parameter and then within the extension open up the MainContent block and access it's properties which wouldn't make my extension very generic
Is there any way i can access the local blocks properties directly with a string or in some other way that still makes this method as generic as it is now.
Thanks in advanced