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?

Re: Re-flunk-tion! by Jon

Jon
Tue Nov 23 16:23:51 CST 2004

William Sullivan <WilliamSullivan@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: Re-flunk-tion! by WilliamSullivan

WilliamSullivan
Tue Nov 23 20:29:05 CST 2004

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.

"Jon Skeet [C# MVP]" wrote:

> William Sullivan <WilliamSullivan@discussions.microsoft.com> wrote:
> > 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.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>

Re: Re-flunk-tion! by Jon

Jon
Wed Nov 24 00:56:52 CST 2004

William Sullivan <WilliamSullivan@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: Re-flunk-tion! by tommy

tommy
Wed Nov 24 05:31:55 CST 2004

Jon Skeet [C# MVP] <skeet@pobox.com> wrote in message news:<MPG.1c0e410a97293a7998b985@msnews.microsoft.com>...
> William Sullivan <WilliamSullivan@discussions.microsoft.com> wrote:
> > 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.

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

Re: Re-flunk-tion! by tommy

tommy
Wed Nov 24 05:33:47 CST 2004

Jon Skeet [C# MVP] <skeet@pobox.com> wrote in message news:<MPG.1c0e410a97293a7998b985@msnews.microsoft.com>...
> William Sullivan <WilliamSullivan@discussions.microsoft.com> wrote:
> > 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.

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

Re: Re-flunk-tion! by Jon

Jon
Wed Nov 24 07:18:35 CST 2004

Tommy Carlier <tommy.carlier@telenet.be> wrote:
> > > 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.
>
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too