时间:2016-02-16 01:22 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【建立自定义的数据驱动的本地化资源provider】,下面是详细的讲解!
建立自定义的数据驱动的本地化资源provider
public class DbSimpleResourceProvider : IResourceProvider, IImplicitResourceProvider
{
private string _ResourceSetName;
private IDictionary _resourceCache;
private DbSimpleResourceProvider()
{ }
public DbSimpleResourceProvider(string virtualPath, string className)
{
_ResourceSetName=className;
}
private IDictionary GetResourceCache(string cultureName)
{
if (cultureName==null)
cultureName="";
if (this._resourceCache==null)
this._resourceCache=new ListDictionary();
IDictionary Resources=this._resourceCache[cultureName] as IDictionary;
if (Resources==null)
{
// *** DEPENDENCY HERE (#1): Using DbResourceDataManager to retrieve resources
// *** Use datamanager to retrieve the resource keys from the database
DbResourceDataManager Data=new DbResourceDataManager();
Resources=Data.GetResourceSet(cultureName as string, this._ResourceSetName);
this._resourceCache[cultureName]=Resources;
}
return Resources;
}
public void ClearResourceCache()
{
this._resourceCache.Clear();
}
object IResourceProvider.GetObject(string ResourceKey, CultureInfo Culture)
{
string CultureName=null;
if (Culture !=null)
CultureName=Culture.Name;
else
CultureName=CultureInfo.CurrentUICulture.Name;
return this.GetObjectInternal(ResourceKey, CultureName);
}
object GetObjectInternal(string ResourceKey, string CultureName)
{
IDictionary Resources=this.GetResourceCache(CultureName);
object value=null;
if (Resources==null)
value=null;
else
value=Resources[ResourceKey];
// *** If we're at a specific culture (en-Us) and there's no value fall back
// *** to the generic culture (en)
if (value==null && CultureName.Length > 3)
{
// *** try again with the 2 letter locale
return GetObjectInternal(ResourceKey,CultureName.Substring(0,2) );
}
// *** If the value is still null get the invariant value
if (value==null)
{
Resources=this.GetResourceCache("");
if (Resources==null)
value=null;
else
value=Resources[ResourceKey];
}
// *** If the value is still null and we're at the invariant culture
// *** let's add a marker that the value is missing
// *** this also allows the pre-compiler to work and never return null
if (value==null && string.IsNullOrEmpty(CultureName))
{
// *** No entry there
value="";
// *** DEPENDENCY HERE (#2): using DbResourceConfiguration and DbResourceDataManager to optionally
// add missing resource keys
// *** Add a key in the repository at least for the Invariant culture
// *** Something's referencing but nothing's there
if (DbResourceConfiguration.Current.AddMissingResources)
new DbResourceDataManager().AddResource(ResourceKey, value.ToString(), "", this._ResourceSetName);
}
return value;
}
关于建立自定义的数据驱动的本地化资源provider的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【ASP】ASP.NET中内嵌页面代码的一个问题-NET-内
- 【As】Asp.net中的页面乱码的问题-sp--pn-ne-et
- 【增加记录】asp.net中获取新增加记录的ID Access
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
