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;
}
}
}
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;
}
}
}