mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Refactoring of CUETools.Codecs.
This commit is contained in:
56
CUETools.Codecs/SRDescriptionAttribute.cs
Normal file
56
CUETools.Codecs/SRDescriptionAttribute.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
/// <summary>
|
||||
/// Localized description attribute
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)]
|
||||
public class SRDescriptionAttribute : DescriptionAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Store a flag indicating whether this has been localized
|
||||
/// </summary>
|
||||
private bool localized;
|
||||
|
||||
/// <summary>
|
||||
/// Resource manager to use;
|
||||
/// </summary>
|
||||
private Type SR;
|
||||
|
||||
/// <summary>
|
||||
/// Construct the description attribute
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
public SRDescriptionAttribute(Type SR, string text)
|
||||
: base(text)
|
||||
{
|
||||
this.localized = false;
|
||||
this.SR = SR;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the return of the description text to localize the text
|
||||
/// </summary>
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!localized)
|
||||
{
|
||||
localized = true;
|
||||
this.DescriptionValue = SR.InvokeMember(
|
||||
this.DescriptionValue,
|
||||
System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Static |
|
||||
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic,
|
||||
null,
|
||||
null,
|
||||
new object[] { }) as string;
|
||||
}
|
||||
|
||||
return base.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user