Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
Created April 4, 2013 09:44
Show Gist options
  • Save mattbrailsford/5309142 to your computer and use it in GitHub Desktop.
Save mattbrailsford/5309142 to your computer and use it in GitHub Desktop.
public static class UmbracoHelperExtensions
{
// These extensions methods are here to bypass an issue with Umbraco.TypedContent method
// wherby if an item is in the trashcan, a YSOD is thrown. The issue has been reported here
// http://issues.umbraco.org/issue/U4-1300
// Once fixed, any uses of TypeContent2 can just be replaced with TypedContent calls
public static IEnumerable<IPublishedContent> TypedContent2(this UmbracoHelper helper, IEnumerable<string> ids)
{
return helper.TypedContent2(ids.ToArray());
}
public static IEnumerable<IPublishedContent> TypedContent2(this UmbracoHelper helper, IEnumerable<int> ids)
{
return helper.TypedContent2(ids.ToArray());
}
public static IEnumerable<IPublishedContent> TypedContent2(this UmbracoHelper helper, params string[] ids)
{
int parsedId;
return helper.TypedContent2(ids.Select(x => int.TryParse(x, out parsedId) ? parsedId : 0).ToArray());
}
public static IEnumerable<IPublishedContent> TypedContent2(this UmbracoHelper helper, params int[] ids)
{
return ids.Select(helper.TypedContent)
.Select(tc => tc.GetType() == typeof(DynamicNull) ? null : tc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment