我在我的应用程序上使用本地化,并希望获取基本语言中使用的Resource文件的基本列表。研究表明,以下陈述应能满足我的需求。

Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
string[] resNames = a.GetManifestResourceNames();


我没有任何错误,只是一个空字符串数组(string[])。我已经在运行IIS Express的本地计算机和生产服务器上对此进行了测试。

在本地查看Assembly变量时,分配的值如下。

 {App_Code.i5gd5jfv, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null}


非常感谢您提供任何帮助!提前致谢!

最佳答案

根据dtb的评论,我发现我没有引用proper assembly。因此,我整理了以下代码,以便为Assembly获取正确的App_GlobalResources,然后获取资源列表。

Assembly[] assemblyList = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblyList)
{
    string assemblyName = assembly.GetName().Name.ToString().Split(new char[] { '.' })[0];

    if (assemblyName == "App_GlobalResources")
    {
        foreach (string s in assembly.GetManifestResourceNames())
        {
            //do stuff with the list of resources.
        }
    }
}


如果有更好的方法,请告诉我!

10-04 21:37
查看更多