···11+// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22+// See the LICENCE file in the repository root for full licence text.
33+44+using System;
55+66+namespace osu.Framework.Localisation
77+{
88+ /// <summary>
99+ /// Describes the values of an <see cref="Enum"/> type by <see cref="LocalisableString"/>s.
1010+ /// </summary>
1111+ /// <typeparam name="T">The <see cref="Enum"/> type.</typeparam>
1212+ public abstract class EnumLocalisationMapper<T> : IEnumLocalisationMapper
1313+ where T : Enum
1414+ {
1515+ /// <summary>
1616+ /// Describes a <typeparamref name="T"/> value by a <see cref="LocalisableString"/>.
1717+ /// </summary>
1818+ /// <param name="value">The value to map.</param>
1919+ /// <returns>The <see cref="LocalisableString"/> describing <paramref name="value"/>.</returns>
2020+ public abstract LocalisableString Map(T value);
2121+ }
2222+2323+ /// <summary>
2424+ /// Marker class for <see cref="EnumLocalisationMapper{T}"/>. Do not use.
2525+ /// </summary>
2626+ internal interface IEnumLocalisationMapper
2727+ {
2828+ }
2929+}
···11+// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22+// See the LICENCE file in the repository root for full licence text.
33+44+using System;
55+using osu.Framework.Extensions;
66+using osu.Framework.Extensions.TypeExtensions;
77+88+namespace osu.Framework.Localisation
99+{
1010+ /// <summary>
1111+ /// Indicates that the values of an enum have <see cref="LocalisableString"/> descriptions.
1212+ /// The descriptions can be retrieved through <see cref="ExtensionMethods.GetLocalisableDescription{T}"/>.
1313+ /// </summary>
1414+ [AttributeUsage(AttributeTargets.Enum)]
1515+ public sealed class LocalisableEnumAttribute : Attribute
1616+ {
1717+ /// <summary>
1818+ /// The <see cref="EnumLocalisationMapper{T}"/> type that maps enum values to <see cref="LocalisableString"/>s.
1919+ /// </summary>
2020+ public readonly Type MapperType;
2121+2222+ /// <summary>
2323+ /// Creates a new <see cref="LocalisableEnumAttribute"/>.
2424+ /// </summary>
2525+ /// <param name="mapperType">The <see cref="EnumLocalisationMapper{T}"/> type that maps enum values to <see cref="LocalisableString"/>s.</param>
2626+ public LocalisableEnumAttribute(Type mapperType)
2727+ {
2828+ MapperType = mapperType;
2929+3030+ if (!typeof(IEnumLocalisationMapper).IsAssignableFrom(mapperType))
3131+ throw new ArgumentException($"Type \"{mapperType.ReadableName()}\" must inherit from {nameof(EnumLocalisationMapper<Enum>)}.", nameof(mapperType));
3232+ }
3333+ }
3434+}