Debugger and watch issue with strings and own defined type

G

Girish

Ok, starting from the basics. Reference types and value types are all
objects underneath.

So, a String is an object as well.

Now, when when we are debugging and we examine the contents of a String
object - the debugger actually shows the value of containing string object
when you keep a watch on the instance variable.

But when I create my OWN type which holds a string inside - and get this
1) Have an implicit conversion from string -> object
2) Have an implicit conversion from object -> string AND
3) Have the ToString() method overridden

The debugger still shows me the value of my object as the fully qualified
class name!

How is the String class object built so that the debugger knows to show the
internal string/byte array, whatever as the value and not the fully
qualified name of the class which should be "System.String" i think.

The code for my class is below.

Thanks,
Girish

StringWrapper
---------------

using System;
namespace test1 {
public class StringWrapper {
private String _val;

public String val {
get { return _val; }
}

public StringWrapper(String val) {
this._val = val;
}

public override string ToString() {
return val;
}

static public implicit operator StringWrapper(String val)
{
val += " (im changed)";
return new StringWrapper(val);
}

static public implicit operator string(StringWrapper val) {
return val.val;
}
}
}
 
M

Mattias Sjögren

How is the String class object built so that the debugger knows to show the
internal string/byte array, whatever as the value and not the fully
qualified name of the class which should be "System.String" i think.

The debugger probably has built in special handling of strings.

But you should check out the file Visual
Studio\Common7\Packages\Debugger\mcee_cs.dat. In it you can modify how
a certain type shows up in the debugger windows.



Mattias
 
A

Alvin Bruney [ASP.NET MVP]

Mattias,
can you use that technique to force the debugger tooltip to display
stringbuilder variables? I really need the ability to hover over a
stringbuilder object and find its values.

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________
 
M

Mattias Sjögren

can you use that technique to force the debugger tooltip to display
stringbuilder variables? I really need the ability to hover over a
stringbuilder object and find its values.

I've never tried so I don't know for sure, but I don't see why not.
Try it!



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top