Home All Groups Group Topic Archive Search About
Author
23 Nov 2004 9:41 PM
William Sullivan
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?
Author
23 Nov 2004 10:23 PM
Jon Skeet [C# MVP]
William Sullivan <WilliamSulli***@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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Are all your drivers up to date? click for free checkup

Author
24 Nov 2004 2:29 AM
William Sullivan
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.

Show quoteHide quote
"Jon Skeet [C# MVP]" wrote:

> William Sullivan <WilliamSulli***@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 - <sk***@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>
Author
24 Nov 2004 6:56 AM
Jon Skeet [C# MVP]
William Sullivan <WilliamSulli***@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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Author
24 Nov 2004 11:31 AM
Tommy Carlier
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MPG.1c0e410a97293a7998b985@msnews.microsoft.com>...
> William Sullivan <WilliamSulli***@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);
Author
24 Nov 2004 1:18 PM
Jon Skeet [C# MVP]
Tommy Carlier <tommy.carl***@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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Author
24 Nov 2004 11:33 AM
Tommy Carlier
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MPG.1c0e410a97293a7998b985@msnews.microsoft.com>...
> William Sullivan <WilliamSulli***@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);

Bookmark and Share