2017-04-17 3 views
0

私は、画像に示されているように私のプロジェクトにグローバルとローカル埋め込みリソースを持っています。Assembly.GetExecutingAssembly()。GetManifestResourceNames()は、App_LocalResourcesからリソースを返しますか?

Resources files in my project with build action as embedded resources

私は機能を持っているResourceText以下のように私は、関数ResourceTextをデバッグ

<input type="search" id="inputCustomerGroupGridSearch" placeholder="<%= ResourceText("PlaceholderSearch")%>" /> 
      <button type="button" id="buttonNewCustomerGroup" style="float: right" class="PrimaryButton"><%=ResourceText("ButtonNew")%></button> 

のラインとしての私のaspxページで呼び出され

   public static string GLOBAL_RESOURCES = "SampleClient.App_GlobalResources.Global.resources"; 

       /// <summary> 
       /// Used in JavaScript/front code to return resource translations for current page or global resource file 
       /// </summary> 
       /// <param name="pResourceKey"></param> 
       /// <returns></returns> 
       /// <remarks></remarks> 
       public string ResourceText(string pResourceKey, bool pGlobalResource = false) 
       { 
        if (string.IsNullOrEmpty(pResourceKey)) throw new ArgumentNullException("ResourceKey cannot be empty"); 

        if (pGlobalResource) 
        { 
         // Find the value from the global resource 

         ResourceManager tResourceManager = new System.Resources.ResourceManager(GLOBAL_RESOURCES.Replace(".resources", ""), this.GetType().BaseType.Assembly); 
         tResourceManager.IgnoreCase = true; 

         string tTranlsation = tResourceManager.GetString(pResourceKey); 

         return string.IsNullOrEmpty(tTranlsation) ? pResourceKey : tTranlsation; 
        } 
        else 
        { 
         string[] tAssemblyNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); 
         try 
         { 
          if (tAssemblyNames.Length >= 1) // There is a local file associated 
          { 
           // Get value from the local resource 
           string tAssemblyName = this.Page.GetType().BaseType.FullName.Insert(this.Page.GetType().BaseType.FullName.LastIndexOf(".") + 1, "App_LocalResources."); 


           string tResName = (from n in tAssemblyNames where n.Contains(tAssemblyName + ".aspx") select n).First().Replace(".resources", ""); 
           ResourceManager tResourceManager = new System.Resources.ResourceManager(tResName, this.GetType().BaseType.Assembly); 

           tResourceManager.IgnoreCase = true; 


           string tTranlsation = tResourceManager.GetString(pResourceKey); 
           return string.IsNullOrEmpty(tTranlsation) ? pResourceKey : tTranlsation; 
          } 
         } 

         catch (Exception ex) 
         { 
          throw (ex); 
          // Check the local resources 
         } 

        } 
        // Fall back 
        return pResourceKey; 
       } 

コード

string[] tAssemblyNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); 

は、 "SampleClient.Modules.Customers.App_LocalResources.Customers.resouces"ではなく "SampleClient.App_GlobalResources.Global.resources"のみを返します。なぜApp_LocalResourcesのリソースがAssembly.GetExecutingAssembly()によって返されないのですか。GetManifestResourceNames()?

答えて

0

解決済み:私のbinフォルダに強力な型付きアセンブリApp_LocalResources.resources.dllを追加しました。 Assembly.GetExecutingAssembly()を実行すると、リソース名にリストされます。GetManifestResourceNames();

したがって、グローバルリソースとローカルリソースの両方に対して自分のResourceText関数を呼び出すことができます。

関連する問題