Re-flunk-tion!

G

Guest

I'm wondering why reflection fails in this instance... I'm trying to do drag
and drop using ListViewItem objects. When I check the DragEventArgs to see
if it has my ListViewItem, I have to use GetDataPresent to test if it's the
data I'm looking for. I have to pass a System.Type object representing the
type of a ListViewItem object. But I've found that Type fails to correctly
identify a ListViewItem. If I try this:
Type f = Type.GetType("System.Windows.Forms.ListViewItem");
f is null. According to MSDN, this should work, as their sample is this:
Type myType1 = Type.GetType("System.Int32");

Am I wrong? What's going on?
 
J

Jon Skeet [C# MVP]

William Sullivan said:
I'm wondering why reflection fails in this instance... I'm trying to do drag
and drop using ListViewItem objects. When I check the DragEventArgs to see
if it has my ListViewItem, I have to use GetDataPresent to test if it's the
data I'm looking for. I have to pass a System.Type object representing the
type of a ListViewItem object. But I've found that Type fails to correctly
identify a ListViewItem. If I try this:
Type f = Type.GetType("System.Windows.Forms.ListViewItem");
f is null. According to MSDN, this should work, as their sample is this:
Type myType1 = Type.GetType("System.Int32");

Am I wrong? What's going on?

You're wrong, because you didn't spot the bit of the documentation
which states:

<quote>
If typeName includes only the name of the Type, this method searches in
the calling object's assembly, then in the mscorlib.dll assembly. If
typeName is fully qualified with the partial or complete assembly name,
this method searches in the specified assembly.
</quote>

Int32 is part of mscorlib; ListViewItem isn't.
 
G

Guest

Okay, so what's the "fully qualifed with the partial or complete assembly
name" of ListViewItem? I'm interested because I thought that
"System.Windows.Forms.ListViewItem" was fully qualified.
 
J

Jon Skeet [C# MVP]

William Sullivan said:
Okay, so what's the "fully qualifed with the partial or complete assembly
name" of ListViewItem?

System.Windows.Forms.ListViewItem, System.Windows.Forms, Version=
1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
I'm interested because I thought that
"System.Windows.Forms.ListViewItem" was fully qualified.

It's fully qualified in terms of namespace, but not assembly.
 
T

Tommy Carlier

Jon Skeet said:
System.Windows.Forms.ListViewItem, System.Windows.Forms, Version=
1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


It's fully qualified in terms of namespace, but not assembly.

If you just want to get the type, use this:
Type t = typeof(System.Windows.Forms.ListView);
 
T

Tommy Carlier

Jon Skeet said:
System.Windows.Forms.ListViewItem, System.Windows.Forms, Version=
1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


It's fully qualified in terms of namespace, but not assembly.

If you just want to get the type, use this:
Type t = typeof(System.Windows.Forms.ListView);
 
J

Jon Skeet [C# MVP]

Tommy Carlier said:
If you just want to get the type, use this:
Type t = typeof(System.Windows.Forms.ListView);

That's fine if you know the type name at compile time, but typically
that isn't the situation when this kind of problem arises.
 

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