看了 杨云 发的” 利用资源文件做多语言版本软件之乐趣 ”感觉,方法并不是很方便,共享一下我的 资源文件 类
其实这个 class 在 HtmlEditor3.1 中就曾经使用过
sealed class Manager #region sealed class Manager
/**/ ///
1<summary>
2 /// 实现对资源文件(resx)的管理
3 /// <seealso cref="ResourceManager"></seealso>
4 /// </summary>
///
1<remarks>
2 /// 暂时用于获取全球化的语言信息资源
3
4 /// Create By lion
5
6 /// 2004-08-11 11:56
7
8 /// Support .Net Framework v1.1.4322
9
10 /// 调用时只要传递 Thread.CurentThread.CurentUICulutre 给那个类就可
11
12 /// </remarks>
///
1<permission cref="System.Security.PermissionSet"> public sealed </permission>
public sealed class Manager
{
/**/ ///
1<summary>
2 /// 资源文件列表
3 /// </summary>
///
1<permission cref="System.Security.PermissionSet"> private </permission>
private static Hashtable _resources;
/**/ ///
1<summary>
2 /// Manager 构造函数
3 /// </summary>
///
1<permission cref="System.Security.PermissionSet"> public </permission>
public Manager()
{}
Function Custom #region Function Custom
/**/ ///
1<summary>
2 /// 确定区域性特定资源的访问
3 /// </summary>
///
1<param name="resxName"/>
资源名称
///
1<permission cref="System.Security.PermissionSet"> internal </permission>
///
1<example>
2 /// <code>
3 /// EnsureResources(resxName);
4 /// </code>
5 /// </example>
internal static void EnsureResources( string resxName)
{
if (_resources == null )
{
_resources = new Hashtable();
}
try
{
if ( ! _resources.ContainsKey(resxName))
{
_resources.Add(resxName, new ResourceManager( " CSDN.AssemblyResourceManager. " + resxName, typeof (CSDN.AssemblyResourceManager.Manager).Assembly));
}
}
catch
{}
}
/**/ ///
1<summary>
2 /// 返回指定的 <see cref="Object"></see> 资源的值
3 /// </summary>
///
1<seealso cref="GetString"></seealso>
///
1<param name="resxName"/>
资源名称
///
1<param name="name"/>
要获取的资源名
///
1<returns> 针对调用方的当前区域性设置而本地化的资源的值。如果不可能有匹配项,则返回空引用(Visual Basic 中为 Nothing)。资源值可以为空引用 (Nothing)。 </returns>
///
1<permission cref="System.Security.PermissionSet"> public </permission>
///
1<exception cref="ArgumentNullException"> name 参数为空引用(Visual Basic 中为 Nothing)。 </exception>
///
1<exception cref="MissingManifestResourceException"> 未找到可用的资源集,并且没有非特定区域性的资源。 </exception>
///
1<example>
2 /// 下面的代码演示如何调用 <see cref="GetObject"></see>
3 /// <code>
4 /// string str = GetObject(resxName, name);
5 /// </code>
6 /// </example>
public static object GetObject( string resxName, string name)
{
return GetObject(resxName, name, null );
}
/**/ ///
1<summary>
2 /// 返回指定的 <see cref="Object"></see> 资源的值
3 /// </summary>
///
1<seealso cref="GetString"></seealso>
///
1<param name="resxName"/>
资源名称
///
1<param name="name"/>
要获取的资源名
///
1<param name="culture"/>
1<see cref="System.Globalization.CultureInfo"></see>
对象,它表示资源被本地化为的区域性。注意,如果尚未为该区域性本地化此资源,则查找将使用区域性的 Parent 属性回退,并在签入非特定语言区域性后停止。 如果该值为空引用(Visual Basic 中为 Nothing),则使用区域性的 CurrentUICulture 属性获取 CultureInfo
///
1<returns> 为指定区域性本地化的资源的值。如果不可能有“最佳匹配”,则返回空引用(Visual Basic 中为 Nothing)。 </returns>
///
1<permission cref="System.Security.PermissionSet"> public </permission>
///
1<exception cref="ArgumentNullException"> name 参数为空引用(Visual Basic 中为 Nothing)。 </exception>
///
1<exception cref="MissingManifestResourceException"> 未找到可用的资源集,并且没有非特定区域性的资源。 </exception>
///
1<example>
2 /// 下面的代码演示如何调用 <see cref="GetObject"></see>
3 /// <code>
4 /// object o = GetObject(resxName, name, culture);
5 /// </code>
6 /// </example>
public static object GetObject( string resxName, string name, CultureInfo culture)
{
EnsureResources(resxName);
ResourceManager res = _resources[resxName] as ResourceManager;
if (res != null )
return res.GetObject(name, culture);
return null ;
}
/**/ ///
1<summary>
2 /// 返回指定的 <see cref="String"></see> 资源的值
3 /// </summary>
///
1<seealso cref="GetObject"></seealso>
///
1<param name="resxName"/>
资源名称
///
1<param name="name"/>
要获取的资源名。
///
1<returns> 针对调用方的当前区域性设置而本地化的资源的值。如果不可能有匹配项,则返回空引用(Visual Basic 中为 Nothing)。 </returns>
///
1<permission cref="System.Security.PermissionSet"> public </permission>
///
1<exception cref="ArgumentNullException"> name 参数为空引用(Visual Basic 中为 Nothing)。 </exception>
///
1<exception cref="MissingManifestResourceException"> 未找到可用的资源集,并且没有非特定区域性的资源。 </exception>
///
1<exception cref="InvalidOperationException"> 指定资源的值不是字符串。 </exception>
///
1<example>
2 /// 下面的代码演示如何调用 <see cref="GetString"></see>
3 /// <code>
4 /// string str = GetString(resxName, name);
5 /// </code>
6 /// </example>
public static string GetString( string resxName, string name)
{
return GetString(resxName, name, null );
}
/**/ ///
1<summary>
2 &nbs</summary>