A game framework written with osu! in mind.
at master 57 lines 2.4 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using osu.Framework.Extensions; 6 7namespace osu.Framework.Localisation 8{ 9 /// <summary> 10 /// Specifies a <see cref="LocalisableString"/>-based description for the target element. 11 /// The description can be retrieved through <see cref="ExtensionMethods.GetLocalisableDescription{T}"/>. 12 /// </summary> 13 /// <remarks> 14 /// The C# language specification 15 /// <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/attributes#attribute-parameter-types"> 16 /// only permits a limited set of parameter types for attributes, 17 /// </a> 18 /// and as such <see cref="LocalisableString"/> instances cannot be passed in directly. 19 /// Therefore usages must pass both the target type in which the <see cref="LocalisableString"/> description is declared, 20 /// as well as the name of the member which contains/returns the <see cref="LocalisableString"/> (using <see langword="nameof"/> for this is strongly encouraged). 21 /// </remarks> 22 /// <example> 23 /// Assuming the following source class from which the <see cref="LocalisableString"/> description should be returned: 24 /// <code> 25 /// class Strings 26 /// { 27 /// public static LocalisableString Example => "example string"; 28 /// } 29 /// </code> 30 /// the attribute should be used in the following way: 31 /// <code> 32 /// [LocalisableDescription(typeof(Strings), nameof(Strings.Example))] 33 /// </code> 34 /// </example> 35 [AttributeUsage(AttributeTargets.All)] 36 public sealed class LocalisableDescriptionAttribute : Attribute 37 { 38 /// <summary> 39 /// The type declaring the static member providing the localisable description. 40 /// </summary> 41 public readonly Type DeclaringType; 42 43 /// <summary> 44 /// The name of the static member providing the localisable description. 45 /// </summary> 46 public readonly string Name; 47 48 /// <summary> 49 /// Creates a new <see cref="LocalisableDescriptionAttribute"/>. 50 /// </summary> 51 public LocalisableDescriptionAttribute(Type declaringType, string name) 52 { 53 DeclaringType = declaringType; 54 Name = name; 55 } 56 } 57}