C# newbie Casting Types

  • Thread starter Thread starter Shayne H
  • Start date Start date
S

Shayne H

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...
 
Hi

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

HTH
Prasad
 
Thanks heaps
Do I feel foolish...
seems I have a sitting in front of the monitor too long problem.
 

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

Back
Top