Which best practice to read resource file.
I am trying below two approaches but each has its own drawback it seems.
Approach 1: Using CreateFileBasedResourceManger function. But due to below code..Handle count is getting increased.
ResourceManager resourceReader = ResourceManager.CreateFileBasedResourceManager("MyResources", appFilePath, null);
string translatedMessage = resourceReader.GetString(keyName);
if (!string.IsNullOrEmpty(translatedMessage))
{
return translatedMessage;
}
else
{
englishKey = keyName.Substring(keyName.Length - 4, 4);
keyName = keyName.Replace(englishKey, "_ENG");
translatedMessage = resourceReader.GetString(keyName);
if (!string.IsNullOrEmpty(translatedMessage))
{
return translatedMessage;
}
throw new FormatterException("Key is not present in the resoucre file");
}
Approach 2 : Using ResourceSet constructor..Handle count is getting reduced but performance has been down.
using (ResourceSet resx = new ResourceSet(appFilePath + "\\MyResources.resources"))
{
string translatedMessage= resx.GetString(keyName);
if (!string.IsNullOrEmpty(translatedMessage))
{
return translatedMessage;
}
else
{
englishKey = keyName.Substring(keyName.Length - 4, 4);
keyName = keyName.Replace(englishKey, "_ENG");
translatedMessage = resx.GetString(keyName);
if (!string.IsNullOrEmpty(translatedMessage))
{
return translatedMessage;
}
throw new FormatterException("Key is not present in the resoucre file");
}
}
Please suggest is there any other way to read resource file by keeping performance up and handle count.