0

What is the proper syntax to obtain a dictionary key value pair when using trace points?

With a property like the following

public Dictionary<string, decimal> SomeDictionary { get; set; }

I am trying to set a break point with actions on the setter method to trace all incoming values. I've tried the following but none of them work.

{value}        'this gives me a count of how many items are in the dictionary

{value.Value}  'throws an exception, 'Value' doesn't exist

{value[Value]} 'the name 'Value' does not exist in the current context

enter image description here

6
  • 1
    what???????????????????????? Commented Mar 10, 2017 at 17:42
  • Did you mean to tag something else like javascript? This is (obviously) not c# syntax, not only would it not return anything it would never even compile. Commented Mar 10, 2017 at 17:43
  • Are you referring to TracePoints in the debugger? Commented Mar 10, 2017 at 17:46
  • yes this is referring to TracePoints while debugging. apologies for confusion, added more tags and picture Commented Mar 10, 2017 at 17:46
  • is value a dictionary or KVP? Commented Mar 10, 2017 at 17:50

2 Answers 2

1

Based on your SomeDictionary:

        public class Example
        {
            public Dictionary<string, decimal> SomeDictionary { get; set; }

            public Example()
            {
                SomeDictionary = new Dictionary<string, decimal>();
                string key = "key";
                SomeDictionary[key] = 10.0M;
            }

        }

        static void Main(string[] args)
        {
            var example = new Example();
            Console.ReadKey();
        }

If we put a tracepoint at the end of the constructor after the dictionary is defined and the key is added - Tracepoint action:

SomeDictionary: {SomeDictionary}; SomeDictionary[key]: {SomeDictionary[key]}

We can inspect the dictionary - Output:

SomeDictionary: Count = 1; SomeDictionary[key]: 10.0
Sign up to request clarification or add additional context in comments.

Comments

0

You can reference the dictionary by using

{ map["key1"] }

or using variable to access the keyvalue pair.

enter image description here

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.