Pregunta

Using C#, I need to do a reverse look up my resource file. I know how to grab a string value using the ResourceManager class but I now want to do the opposite. Will I need to load the resource file into an xml file first?

The reason I want to do this is because I have some hard coded enums that are in English and my resource file contains English to Spanish keys and values. So when my code is looking for WorkflowSupport.Completed enum but the workflow returns "Terminado" rather then "Completed", it will fail.

What I am specifically trying to do is:

I have a SharePoint workflow that returns the step the workflow is in. I have localized this workflow, so instead of returning "Completed" it will return "Terminado". I have an enum with five hard coded values that match the various states of the workflow (Completed, Cancelled, Reassigned, Terminated and Processing). Since the workflow returns "Terminado" instead of "Completed", the code can't match "Terminado" to any of the enum values and fails. I want to do a reverse lookup in my resource file, so if I get a value like "Terminado" I can return "Completed" and successfully match it to the enum member "Completed".

If there is a better way to do this, I am all ears :)

¿Fue útil?

Solución

Instead of comparing the string values of the enum you have to compare their values.

For example, if you are working with a Combobox, you have a text and a value (numeric value of the enum) for each item, the user selects the text and you just cast the value back to your enum type.

Are you using Forms or WPF?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top