PC Review


Reply
Thread Tools Rate Thread

C# newbie Casting Types

 
 
Shayne H
Guest
Posts: n/a
 
      3rd Sep 2003
I am trying to convert the following to VB.NET code

Type t = notifyIcon1.GetType()
IntPtr window =
((NativeWindow)t.GetField("window",System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic).GetValue(notifyIcon1)).Handle;

As I understand it, the fragment:
window = ((NativeWindow)t.GetField(...
is casting an object of type System.Reflection.FieldInfo to NativeWindow
Am I interpreting that correctly?

I do not seem able to make the necessary conversion in VB.NET
This is as far as I've got:

Dim typ as Type = notifyIcon1.GetType()
Dim fieldInfo As System.Reflection.FieldInfo = typ.GetField("window",
Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
Dim window As IntPtr = CType(fieldInfo, NativeWindow).Handle

But type FieldInfo cannot be converted to NativeWindow...
--
Thanks for any help,
Shayne H



 
Reply With Quote
 
 
 
 
Prasad
Guest
Posts: n/a
 
      3rd Sep 2003
Hi

It is not converting FieldInfo to NativeWindow instead the Field's value to
NativeWindow. See you missed .GetValue(notifyIcon1)

HTH
Prasad
"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:#(E-Mail Removed)...
> I am trying to convert the following to VB.NET code
>
> Type t = notifyIcon1.GetType()
> IntPtr window =
> ((NativeWindow)t.GetField("window",System.Reflection.BindingFlags.Instance

|
> System.Reflection.BindingFlags.NonPublic).GetValue(notifyIcon1)).Handle;
>
> As I understand it, the fragment:
> window = ((NativeWindow)t.GetField(...
> is casting an object of type System.Reflection.FieldInfo to NativeWindow
> Am I interpreting that correctly?
>
> I do not seem able to make the necessary conversion in VB.NET
> This is as far as I've got:
>
> Dim typ as Type = notifyIcon1.GetType()
> Dim fieldInfo As System.Reflection.FieldInfo = typ.GetField("window",
> Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
> Dim window As IntPtr = CType(fieldInfo, NativeWindow).Handle
>
> But type FieldInfo cannot be converted to NativeWindow...
> --
> Thanks for any help,
> Shayne H
>
>
>



 
Reply With Quote
 
Shayne H
Guest
Posts: n/a
 
      3rd Sep 2003
Thanks heaps
Do I feel foolish...
seems I have a sitting in front of the monitor too long problem.

"Prasad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> It is not converting FieldInfo to NativeWindow instead the Field's value

to
> NativeWindow. See you missed .GetValue(notifyIcon1)
>
> HTH
> Prasad
> "Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
> news:#(E-Mail Removed)...
> > I am trying to convert the following to VB.NET code
> >
> > Type t = notifyIcon1.GetType()
> > IntPtr window =
> >

((NativeWindow)t.GetField("window",System.Reflection.BindingFlags.Instance
> |
> > System.Reflection.BindingFlags.NonPublic).GetValue(notifyIcon1)).Handle;
> >
> > As I understand it, the fragment:
> > window = ((NativeWindow)t.GetField(...
> > is casting an object of type System.Reflection.FieldInfo to NativeWindow
> > Am I interpreting that correctly?
> >
> > I do not seem able to make the necessary conversion in VB.NET
> > This is as far as I've got:
> >
> > Dim typ as Type = notifyIcon1.GetType()
> > Dim fieldInfo As System.Reflection.FieldInfo = typ.GetField("window",
> > Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
> > Dim window As IntPtr = CType(fieldInfo, NativeWindow).Handle
> >
> > But type FieldInfo cannot be converted to NativeWindow...
> > --
> > Thanks for any help,
> > Shayne H
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Down-casting of Typed Collection (Casting Generic Types?) conchur Microsoft C# .NET 1 3rd Jul 2006 11:45 AM
Re: Dynamic casting between types Jon Skeet [C# MVP] Microsoft Dot NET Framework 1 14th Sep 2004 12:13 PM
Re: Dynamic casting between types saurabh Microsoft Dot NET Framework 0 14th Sep 2004 09:27 AM
Casting inherited types Jax Microsoft C# .NET 2 9th Jan 2004 12:25 PM
C# newbie Casting Types Shayne H Microsoft C# .NET 2 3rd Sep 2003 07:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:44 AM.