Files
Umbraco-CMS/src/Umbraco.Web/Dynamics/ExtensionMethods.cs
Shannon Deminick 54e5140d6a Added more extension methods to our strongly typed IPublishedContent object and IEnumerable<IPublishedContent> to match all of the available methods
that are on the DynamicPublishedContent object. Added more unit tests for all of these classes.
Moved some of the Dynamic objects into the web project which simplifies things quite a bit as some of these classes require access to the biz logic layer.
Now we have intellisense for all of the nice magical methods that were on DynamicPublishedContent on our strongly typed object!
2012-10-04 03:26:56 +05:00

33 lines
1.1 KiB
C#

using System;
using System.Linq;
using Umbraco.Web.Models;
namespace Umbraco.Web.Dynamics
{
internal static class ExtensionMethods
{
public static DynamicPublishedContentList Random(this DynamicPublishedContentList all, int min, int max)
{
//get a random number generator
Random r = new Random();
//choose the number of elements to be returned between Min and Max
int Number = r.Next(min, max);
//Call the other method
return Random(all, Number);
}
public static DynamicPublishedContentList Random(this DynamicPublishedContentList all, int max)
{
//Randomly order the items in the set by a Guid, Take the correct number, and return this wrapped in a new DynamicNodeList
return new DynamicPublishedContentList(all.Items.OrderBy(x => Guid.NewGuid()).Take(max));
}
public static DynamicPublishedContent Random(this DynamicPublishedContentList all)
{
return all.Items.OrderBy(x => Guid.NewGuid()).First();
}
}
}