Is it possible to assign a System.Diagnostics.DebuggerDisplay attribute to the definition of a Dictionary?
e.g.
Dictionary<int, SomeClass>
[System.Diagnostics.DebuggerDisplay("{Info,nq}")]
public class SomeClass{
string code {get;set;}
public string Info { get { return "info" + code; }}
}
// place an attribute here??
[System.Diagnostics.DebuggerDisplay("{???,nq}")]
Dictionary<int, SomeClass> dict = new Dictionary<int, SomeClass>();
Let’s see how to add a key:value pair to dictionary in Python. Code #1: Using Subscript notation. This method will create a new key:value pair on a dictionary by assigning a value to that key. # Python program to add a key:value pair to dictionary. dict = {'key1':'geeks', 'key2':'for'}.
The DebuggerDisplay attribute has a single argument, which is a string to be displayed in the value column for instances of the type. This string can contain braces ( { and } ). Text within a pair of braces is evaluated as a field, property or method.
Key-value pairs may be added when building a JavaScript dictionary; however, these techniques can also add values. The key stands for the identifier of the unique key, and the value is the corresponding data the key relates to.
The key stands for the identifier of the unique key, and the value is the corresponding data the key relates to. If the dictionary already includes the name you have supplied as the key, you could either change your key or use the following code to update the value. Accessing things is likewise fairly basic; the following code may be used.
EDIT: see also this answer.
I haven't tried it, but from the documentation, it's possible to apply this attribute at the assembly level. So in theory, you could do something like this:
[assembly: DebuggerDisplay("{Key,nq}: {Value,nq}", Target = typeof(KeyValuePair<int, SomeClass>))]
I'd be surprised if it lets you get away with specifying a Target
which is an open generic type, e.g. Target = typeof(KeyValuePair<,>)
which would work for a KVP of any type. But if you need that, it's worth a try!
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