using System.Net; using Umbraco.Core.Strings; namespace Umbraco.Core.Models.PublishedContent { /// /// Represents an item in an array that stores its own index and the total count. /// /// The type of the content. public class IndexedArrayItem { /// /// Initializes a new instance of the class. /// /// The content. /// The index. public IndexedArrayItem(TContent content, int index) { Content = content; Index = index; } /// /// Gets the content. /// /// /// The content. /// public TContent Content { get; } /// /// Gets the index. /// /// /// The index. /// public int Index { get; } /// /// Gets the total count. /// /// /// The total count. /// public int TotalCount { get; set; } /// /// Determines whether this item is the first. /// /// /// true if this item is the first; otherwise, false. /// public bool IsFirst() { return Index == 0; } /// /// If this item is the first, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsFirst(string valueIfTrue) { return IsFirst(valueIfTrue, string.Empty); } /// /// If this item is the first, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsFirst(string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsFirst() ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is not the first. /// /// /// true if this item is not the first; otherwise, false. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public bool IsNotFirst() { return IsFirst() == false; } /// /// If this item is not the first, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotFirst(string valueIfTrue) { return IsNotFirst(valueIfTrue, string.Empty); } /// /// If this item is not the first, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotFirst(string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsNotFirst() ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is at the specified . /// /// The index. /// /// true if this item is at the specified ; otherwise, false. /// public bool IsIndex(int index) { return Index == index; } /// /// If this item is at the specified , the HTML encoded will be returned; otherwise, . /// /// The index. /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsIndex(int index, string valueIfTrue) { return IsIndex(index, valueIfTrue, string.Empty); } /// /// If this item is at the specified , the HTML encoded will be returned; otherwise, . /// /// The index. /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsIndex(int index, string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsIndex(index) ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is at an index that can be divided by the specified . /// /// The modulus. /// /// true if this item is at an index that can be divided by the specified ; otherwise, false. /// public bool IsModZero(int modulus) { return Index % modulus == 0; } /// /// If this item is at an index that can be divided by the specified , the HTML encoded will be returned; otherwise, . /// /// The modulus. /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsModZero(int modulus, string valueIfTrue) { return IsModZero(modulus, valueIfTrue, string.Empty); } /// /// If this item is at an index that can be divided by the specified , the HTML encoded will be returned; otherwise, . /// /// The modulus. /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsModZero(int modulus, string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsModZero(modulus) ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is not at an index that can be divided by the specified . /// /// The modulus. /// /// true if this item is not at an index that can be divided by the specified ; otherwise, false. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public bool IsNotModZero(int modulus) { return IsModZero(modulus) == false; } /// /// If this item is not at an index that can be divided by the specified , the HTML encoded will be returned; otherwise, . /// /// The modulus. /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotModZero(int modulus, string valueIfTrue) { return IsNotModZero(modulus, valueIfTrue, string.Empty); } /// /// If this item is not at an index that can be divided by the specified , the HTML encoded will be returned; otherwise, . /// /// The modulus. /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotModZero(int modulus, string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsNotModZero(modulus) ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is not at the specified . /// /// The index. /// /// true if this item is not at the specified ; otherwise, false. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public bool IsNotIndex(int index) { return IsIndex(index) == false; } /// /// If this item is not at the specified , the HTML encoded will be returned; otherwise, . /// /// The index. /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotIndex(int index, string valueIfTrue) { return IsNotIndex(index, valueIfTrue, string.Empty); } /// /// If this item is at the specified , the HTML encoded will be returned; otherwise, . /// /// The index. /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotIndex(int index, string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsNotIndex(index) ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is the last. /// /// /// true if this item is the last; otherwise, false. /// public bool IsLast() { return Index == TotalCount - 1; } /// /// If this item is the last, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsLast(string valueIfTrue) { return IsLast(valueIfTrue, string.Empty); } /// /// If this item is the last, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsLast(string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsLast() ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is not the last. /// /// /// true if this item is not the last; otherwise, false. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public bool IsNotLast() { return IsLast() == false; } /// /// If this item is not the last, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotLast(string valueIfTrue) { return IsNotLast(valueIfTrue, string.Empty); } /// /// If this item is not the last, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsNotLast(string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsNotLast() ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is at an even index. /// /// /// true if this item is at an even index; otherwise, false. /// public bool IsEven() { return Index % 2 == 0; } /// /// If this item is at an even index, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsEven(string valueIfTrue) { return IsEven(valueIfTrue, string.Empty); } /// /// If this item is at an even index, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsEven(string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsEven() ? valueIfTrue : valueIfFalse)); } /// /// Determines whether this item is at an odd index. /// /// /// true if this item is at an odd index; otherwise, false. /// public bool IsOdd() { return Index % 2 == 1; } /// /// If this item is at an odd index, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsOdd(string valueIfTrue) { return IsOdd(valueIfTrue, string.Empty); } /// /// If this item is at an odd index, the HTML encoded will be returned; otherwise, . /// /// The value if true. /// The value if false. /// /// The HTML encoded value. /// // TODO: This method should be removed or moved to an extension method on HtmlHelper. public IHtmlEncodedString IsOdd(string valueIfTrue, string valueIfFalse) { return new HtmlEncodedString(WebUtility.HtmlEncode(IsOdd() ? valueIfTrue : valueIfFalse)); } } }