0

In my wp7 application I do a web request that returns a status code like 100, 110, etc. Each status code is associated with a status message. This status messages are localized in my application.

E.g.

m100 'OK'
m110 'Text was empty'

I want to show this text in a message box like this. contents gives us the status code as string value.

var s = 
    MessageBox.Show(AppResources.m100, AppResources.Notice, MessageBoxButton.OK);

But I don't want to specify a message box for each message. I want to handle this in a dynamic way like this.

var s = 
    MessageBox.Show(AppResources.m+contents, AppResources.Notice, 
                    MessageBoxButton.OK);

Any idea how to do this?

2
  • Instead of trying to access the name of the variable, you can try to use a Dictionnay like structure (or hashmap, hashtable, etc..) to store the messages and use m100, m110... as a key to access them. That way you will have your message by doing: myDictionnary.get(M100) Commented Apr 7, 2012 at 10:59
  • @olchauvin, I think the AppResources class is generated from a resource file, so the dictionary is already there. Commented Apr 7, 2012 at 11:00

1 Answer 1

4

You should be able to use the ResourceManager to get the value:

AppResources.ResourceManager.GetString("m" + contents)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.