Fixes overloads for TypedMedia, TypedContent, Content, Media calls on UmbracoHelper now that
GetPropertyValue returns 'object'
This commit is contained in:
@@ -423,6 +423,11 @@ namespace Umbraco.Web
|
||||
|
||||
#region Content
|
||||
|
||||
public IPublishedContent TypedContent(object id)
|
||||
{
|
||||
return TypedDocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
public IPublishedContent TypedContent(int id)
|
||||
{
|
||||
return TypedDocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
@@ -433,6 +438,11 @@ namespace Umbraco.Web
|
||||
return TypedDocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedContent(params object[] ids)
|
||||
{
|
||||
return TypedDocumentsbyIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedContent(params int[] ids)
|
||||
{
|
||||
return TypedDocumentsbyIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids);
|
||||
@@ -443,6 +453,11 @@ namespace Umbraco.Web
|
||||
return TypedDocumentsbyIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<object> ids)
|
||||
{
|
||||
return TypedContent(ids.ToArray());
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<string> ids)
|
||||
{
|
||||
return TypedContent(ids.ToArray());
|
||||
@@ -453,6 +468,11 @@ namespace Umbraco.Web
|
||||
return TypedContent(ids.ToArray());
|
||||
}
|
||||
|
||||
public dynamic Content(object id)
|
||||
{
|
||||
return DocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
public dynamic Content(int id)
|
||||
{
|
||||
return DocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
@@ -463,6 +483,11 @@ namespace Umbraco.Web
|
||||
return DocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
public dynamic Content(params object[] ids)
|
||||
{
|
||||
return DocumentByIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids);
|
||||
}
|
||||
|
||||
public dynamic Content(params int[] ids)
|
||||
{
|
||||
return DocumentByIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids);
|
||||
@@ -473,6 +498,11 @@ namespace Umbraco.Web
|
||||
return DocumentByIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids);
|
||||
}
|
||||
|
||||
public dynamic Content(IEnumerable<object> ids)
|
||||
{
|
||||
return Content(ids.ToArray());
|
||||
}
|
||||
|
||||
public dynamic Content(IEnumerable<int> ids)
|
||||
{
|
||||
return Content(ids.ToArray());
|
||||
@@ -487,6 +517,21 @@ namespace Umbraco.Web
|
||||
|
||||
#region Media
|
||||
|
||||
/// <summary>
|
||||
/// Overloaded method accepting an 'object' type
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass
|
||||
/// this result in to this method.
|
||||
/// This method will throw an exception if the value is not of type int or string.
|
||||
/// </remarks>
|
||||
public IPublishedContent TypedMedia(object id)
|
||||
{
|
||||
return TypedDocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore);
|
||||
}
|
||||
|
||||
public IPublishedContent TypedMedia(int id)
|
||||
{
|
||||
return TypedDocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore);
|
||||
@@ -497,6 +542,11 @@ namespace Umbraco.Web
|
||||
return TypedDocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedMedia(params object[] ids)
|
||||
{
|
||||
return TypedDocumentsbyIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedMedia(params int[] ids)
|
||||
{
|
||||
return TypedDocumentsbyIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids);
|
||||
@@ -507,6 +557,11 @@ namespace Umbraco.Web
|
||||
return TypedDocumentsbyIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<object> ids)
|
||||
{
|
||||
return TypedMedia(ids.ToArray());
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<int> ids)
|
||||
{
|
||||
return TypedMedia(ids.ToArray());
|
||||
@@ -517,6 +572,11 @@ namespace Umbraco.Web
|
||||
return TypedMedia(ids.ToArray());
|
||||
}
|
||||
|
||||
public dynamic Media(object id)
|
||||
{
|
||||
return DocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore);
|
||||
}
|
||||
|
||||
public dynamic Media(int id)
|
||||
{
|
||||
return DocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore);
|
||||
@@ -527,6 +587,11 @@ namespace Umbraco.Web
|
||||
return DocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore);
|
||||
}
|
||||
|
||||
public dynamic Media(params object[] ids)
|
||||
{
|
||||
return DocumentByIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids);
|
||||
}
|
||||
|
||||
public dynamic Media(params int[] ids)
|
||||
{
|
||||
return DocumentByIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids);
|
||||
@@ -537,6 +602,11 @@ namespace Umbraco.Web
|
||||
return DocumentByIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids);
|
||||
}
|
||||
|
||||
public dynamic Media(IEnumerable<object> ids)
|
||||
{
|
||||
return Media(ids.ToArray());
|
||||
}
|
||||
|
||||
public dynamic Media(IEnumerable<int> ids)
|
||||
{
|
||||
return Media(ids.ToArray());
|
||||
@@ -551,6 +621,26 @@ namespace Umbraco.Web
|
||||
|
||||
#region Used by Content/Media
|
||||
|
||||
/// <summary>
|
||||
/// Overloaded method accepting an 'object' type
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="store"> </param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass
|
||||
/// this result in to this method.
|
||||
/// This method will throw an exception if the value is not of type int or string.
|
||||
/// </remarks>
|
||||
private IPublishedContent TypedDocumentById(object id, IPublishedStore store)
|
||||
{
|
||||
if (id is string)
|
||||
return TypedDocumentById((string)id, store);
|
||||
if (id is int)
|
||||
return TypedDocumentById((int)id, store);
|
||||
throw new InvalidOperationException("The value of parameter 'id' must be either a string or an integer");
|
||||
}
|
||||
|
||||
private IPublishedContent TypedDocumentById(int id, IPublishedStore store)
|
||||
{
|
||||
var doc = store.GetDocumentById(UmbracoContext.Current, id);
|
||||
@@ -565,6 +655,22 @@ namespace Umbraco.Web
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overloaded method accepting an 'object' type
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="store"> </param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass
|
||||
/// this result in to this method.
|
||||
/// This method will throw an exception if the value is not of type int or string.
|
||||
/// </remarks>
|
||||
private IEnumerable<IPublishedContent> TypedDocumentsbyIds(IPublishedStore store, params object[] ids)
|
||||
{
|
||||
return ids.Select(eachId => TypedDocumentById(eachId, store));
|
||||
}
|
||||
|
||||
private IEnumerable<IPublishedContent> TypedDocumentsbyIds(IPublishedStore store, params int[] ids)
|
||||
{
|
||||
return ids.Select(eachId => TypedDocumentById(eachId, store));
|
||||
@@ -575,6 +681,26 @@ namespace Umbraco.Web
|
||||
return ids.Select(eachId => TypedDocumentById(eachId, store));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overloaded method accepting an 'object' type
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="store"> </param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass
|
||||
/// this result in to this method.
|
||||
/// This method will throw an exception if the value is not of type int or string.
|
||||
/// </remarks>
|
||||
private dynamic DocumentById(object id, IPublishedStore store)
|
||||
{
|
||||
if (id is string)
|
||||
return DocumentById((string)id, store);
|
||||
if (id is int)
|
||||
return DocumentById((int)id, store);
|
||||
throw new InvalidOperationException("The value of parameter 'id' must be either a string or an integer");
|
||||
}
|
||||
|
||||
private dynamic DocumentById(int id, IPublishedStore store)
|
||||
{
|
||||
var doc = store.GetDocumentById(UmbracoContext.Current, id);
|
||||
@@ -591,6 +717,25 @@ namespace Umbraco.Web
|
||||
: new DynamicNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overloaded method accepting an 'object' type
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="store"> </param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass
|
||||
/// this result in to this method.
|
||||
/// This method will throw an exception if the value is not of type int or string.
|
||||
/// </remarks>
|
||||
private dynamic DocumentByIds(IPublishedStore store, params object[] ids)
|
||||
{
|
||||
var nodes = ids.Select(eachId => DocumentById(eachId, store))
|
||||
.Where(x => !TypeHelper.IsTypeAssignableFrom<DynamicNull>(x))
|
||||
.Cast<DynamicPublishedContent>();
|
||||
return new DynamicPublishedContentList(nodes);
|
||||
}
|
||||
|
||||
private dynamic DocumentByIds(IPublishedStore store, params int[] ids)
|
||||
{
|
||||
var nodes = ids.Select(eachId => DocumentById(eachId, store))
|
||||
|
||||
Reference in New Issue
Block a user