namespace Zinnia.Extension
{
using System;
using UnityEngine;
///
/// Static methods for the Type.
///
public static class EnumExtensions
{
///
/// Gets the value based on the given index.
///
/// The type.
/// The index to retrieve from. In case this index is out of bounds for the it will be clamped within the valid bounds.
/// The value for the index.
public static T GetByIndex(int index)
{
return (T)(object)Mathf.Clamp(index, 0, Enum.GetValues(typeof(T)).Length - 1);
}
///
/// Gets the value based of the representation of the type.
///
/// The type.
/// The type representation.
/// The value for the type representation.
public static T GetByString(string value)
{
return (T)Enum.Parse(typeof(T), value.ToString(), true);
}
}
}