473,378 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

IsFamily with Friend and MethodInfo

Question
Hello,

I'm trying to get a MethodInfo class with this code:

---------------------------------------------
Imports System.Reflection

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim myType As Type = GetType(A)
Dim mi As MethodInfo = myType.GetMethod("firstMethod",
BindingFlags.NonPublic Or BindingFlags.Public)

If Not mi Is Nothing Then MsgBox("we have it !")

End Sub

End Class

Public Class A
Friend Sub firstMethod()
MsgBox("message from class A")
End Sub
End Class
---------------------------------------------
But methodinfo is always Nothing !

If I make firstMethod a PUBLIC sub it works without the binding flags, but
what I want is to obtain a methodInfo instantiated for a Friend method, and
its property "isFamily" being TRUE...
Can you help me, please ?

Thanks in advance,

Roger Tranchez
..NET 2005 and DB developer
Feb 12 '07 #1
4 2599
Roger,
>But methodinfo is always Nothing !

If I make firstMethod a PUBLIC sub it works without the binding flags, but
what I want is to obtain a methodInfo instantiated for a Friend method, and
its property "isFamily" being TRUE...
Can you help me, please ?

Try including BindingFlags.Instance.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 12 '07 #2
Hi,

It works, thanks a lot. I searched the web for an explanation of
"BindingFlags.Instance", but I don't fully understand it, I'm sorry...

I think maybe it is because when I do a gettype I'm getting a "type
INSTANCE" of my class ? if so,....

Why it is NOT necessary to put this flag in case of a PUBLIC method with the
same class (changing from "FRIEND" or "PROTECTED sub" to "sub" or "PUBLIC
sub"...

Thanks !

--
Roger Tranchez
..NET 2005 and DB developer
"Mattias Sjögren" wrote:
Roger,
But methodinfo is always Nothing !

If I make firstMethod a PUBLIC sub it works without the binding flags, but
what I want is to obtain a methodInfo instantiated for a Friend method, and
its property "isFamily" being TRUE...
Can you help me, please ?


Try including BindingFlags.Instance.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 13 '07 #3
Roger Tranchez <Ro***********@discussions.microsoft.comwrote:
It works, thanks a lot. I searched the web for an explanation of
"BindingFlags.Instance", but I don't fully understand it, I'm sorry...
It's because the method you're looking for is an instance method.
I think maybe it is because when I do a gettype I'm getting a "type
INSTANCE" of my class ? if so,....

Why it is NOT necessary to put this flag in case of a PUBLIC method with the
same class (changing from "FRIEND" or "PROTECTED sub" to "sub" or "PUBLIC
sub"...
When you call the overload of GetMethod which doesn't take a
BindingFlags parameter, it looks for static and instance methods
automatically.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 13 '07 #4
Absolutely clear now, thanks a lot !

Roger
Feb 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: AngryGerbil | last post by:
hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an ice pick into my eye! I...
2
by: Abdessamad Belangour | last post by:
Hi, I would like please to know how to get the concurrency kind of a methodInfo object. That is, which method of a methodInfo object tells that a call to a method is : "sequential", "guarded" or...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
8
by: AngryGerbil | last post by:
hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an ice pick into my eye! I...
3
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
2
by: Phill W. | last post by:
For some time, I've been adding "trace level" logging to my code using Imports System.Reflection Private Function XYZ( a1 as A, b1 as B, c1 as C, ... TRACE.Log(...
1
by: ian | last post by:
Hi, I can't find a solution to this, so I've brought it to the experts. Using reflection I can get a MethodInfo object pointing at an assembly's method. Where I have a MethodInfo object...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
1
by: tesvit | last post by:
Hi there, I am working on a class library that should incpect a given class, make a delegate to a get Property and use it later on. Here is the code snippet: public delegate int...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.