I tried to understand the source code (!). This is not a simple call to ToString() .
There a internal class System.Windows.Forms.Formatter does some things. As a result, he creates a converter. This is roughly equivalent to:
var conv = System.ComponentModel.TypeDescriptor.GetConverter(tc1.GetType());
where tc1 is TestContol from your question. Now, if we used TestClass tcl , which does not implement any interfaces, this would give us a converter that will eventually call ToString() .
But in this example, we use tc1 , and this is System.ComponentModel.IComponent . Therefore, our conv becomes a System.ComponentModel.ComponentConverter . It uses Site for IComponent . When we speak:
string result = conv.ConvertTo(tc1, typeof(string));
and Site is null, we get the empty string "" that you saw in your combo box. If there was a Site , he would use his Name .
To demonstrate this, put the following in your TestControl instance TestControl :
public TestConrol() { InitializeComponent(); Site = new DummySite();
where DummySite is something like:
class DummySite : ISite { public IComponent Component { get { throw new NotImplementedException(); } } public IContainer Container { get { throw new NotImplementedException(); } } public bool DesignMode { get { throw new NotImplementedException(); } } public string Name { get { return "asd";
source share