-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/OSharp.Utils/Localized/LocalizedDescriptionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="LocalizedDescriptionAttribute.cs" company="OSharp开源团队"> | ||
// Copyright (c) 2014-2024 OSharp. All rights reserved. | ||
// </copyright> | ||
// <site>http://www.osharp.org</site> | ||
// <last-editor>gmf</last-editor> | ||
// <last-date>2024-09-06 10:09</last-date> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Resources; | ||
|
||
|
||
namespace OSharp.Localized | ||
{ | ||
/// <summary> | ||
/// 本地化描述类特性 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.All)] | ||
public class LocalizedDescriptionAttribute : DescriptionAttribute | ||
{ | ||
private readonly string _resourceKey; | ||
private readonly ResourceManager _resourceManager; | ||
|
||
public LocalizedDescriptionAttribute(string resourceKey, Type resourceType) | ||
{ | ||
_resourceKey = resourceKey; | ||
_resourceManager = new ResourceManager(resourceType); | ||
} | ||
|
||
/// <summary>Gets the description stored in this attribute.</summary> | ||
/// <returns>The description stored in this attribute.</returns> | ||
public override string Description | ||
{ | ||
get | ||
{ | ||
var description = _resourceManager.GetString(_resourceKey, CultureInfo.CurrentCulture); | ||
return string.IsNullOrEmpty(description) ? $"[{_resourceKey}]" : description; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters