using System;
using System.Collections;
using System.Collections.Generic;
namespace Umbraco.Core.Models.PublishedContent
{
///
/// Manages the built-in fallback policies.
///
public struct Fallback : IEnumerable
{
private readonly int[] _values;
///
/// Initializes a new instance of the struct with values.
///
private Fallback(int[] values)
{
_values = values;
}
///
/// Gets an ordered set of fallback policies.
///
///
public static Fallback To(params int[] values) => new Fallback(values);
///
/// Do not fallback.
///
public const int None = 0;
///
/// Fallback to default value.
///
public const int DefaultValue = 1;
///
/// Gets the fallback to default value policy.
///
public static Fallback ToDefaultValue => new Fallback(new[] { DefaultValue });
///
/// Fallback to other languages.
///
public const int Language = 2;
///
/// Gets the fallback to language policy.
///
public static Fallback ToLanguage => new Fallback(new[] { Language });
///
/// Fallback to tree ancestors.
///
public const int Ancestors = 3;
///
/// Gets the fallback to tree ancestors policy.
///
public static Fallback ToAncestors => new Fallback(new[] { Ancestors });
///
public IEnumerator GetEnumerator()
{
return ((IEnumerable)_values ?? Array.Empty()).GetEnumerator();
}
///
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}