Here's how my RESX file look like:
Name Value Comments
Rule_seconds seconds seconds
Rule_Sound Sound Sound
What I want is: Name by string Value, something like below:
public string GetResxNameByValue(string value)
{
// some code to get name value
}
And implement it like below:
string str = GetResxNameByValue("seconds");
so that str
will return Rule_seconds
Thanks!
This could work
private string GetResxNameByValue(string value)
{
System.Resources.ResourceManager rm = new System.Resources.ResourceManager("YourNamespace.YourResxFileName", this.GetType().Assembly);
var entry=
rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
.OfType<DictionaryEntry>()
.FirstOrDefault(e => e.Value.ToString() ==value);
var key = entry.Key.ToString();
return key;
}
With some additional error checking..
you can access directly by passing key:
public string gtresource(string rulename)
{
string value = null;
System.Resources.ResourceManager RM = new System.Resources.ResourceManager("CodedUITestProject1.Resource1", this.GetType().Assembly);
value = RM.GetString(rulename).ToString();
if(value !=null && value !="")
{
return value;
}
else
{
return "";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With