ListViewItem and ListViewSubItem

  • Thread starter Klaudiusz Bryja
  • Start date
K

Klaudiusz Bryja

Hi,

I have some problem. I try to get ListViewSubItem type using:

Type t = (new
Form).GetType().Assembly.GetType("System.Windows.Forms.ListViewItem.ListViewSubItem")

but I get t == null. I notice that I can do that using:

Type t = (new
Form).GetType().Assembly.GetType("System.Windows.Forms.ListViewItem
+ListViewSubItem")

Why I have to use "+" sign in namespace? What does it mean? Whay in
msdn is ListViewItem.ListViewSubItem not ListViewItem+ListViewSubItem?

Best regards,
Klaudiusz
 
M

Marc Gravell

+ is the token used internally to indicate nested classes, rather than
classes within a namespace. However, there is no need to use strings here:

Type type = typeof(System.Windows.Forms.ListViewItem.ListViewSubItem);

Marc
 
P

Pavel Minaev

Why I have to use "+" sign in namespace? What does it mean? Whay in
msdn is ListViewItem.ListViewSubItem not ListViewItem+ListViewSubItem?

"+" is a reflection-specific way of denoting nested classes. In C# you
can use "." because the compiler handles this for you; however, this
means that in C#, you cannot have a namespace that contains another
namespace and a class with the same name (CLS forbids this as well, by
the way). CLR itself does not restrict such a thing, however, so you
can write it in IL and compile using ilasm, for example, and
reflection should be able to handle any valid CLR assembly, whether it
is generated by C# or something else, and whether it is CLS-compliant
or not, so it had to make this explicit.
 

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