473,513 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BindingFlags.Internal, where is that?

TEK
When using reflection, the Type.GetProperty method has the following
signature:
Type.GetProperty(String, BindingFlags)

The doc says:
a.. Specify BindingFlags.Public to include public properties in the search.
a.. Specify BindingFlags.NonPublic to include non-public properties (that
is, private and protected properties) in the search.

But how the heck do I get access to the Internal methods???
Specifying BindingFlags.Public | BindingFlags.NonPublic causes the internal
methods to not be found.

Does anyone have any hint about what to do to get the internal methods as
well?

Regards, TEK
Nov 16 '05 #1
5 14800
"TEK" <tr***************@hotmail.com> wrote:
But how the heck do I get access to the Internal methods???
Specifying BindingFlags.Public | BindingFlags.NonPublic causes the
internal methods to not be found.


NonPublic gets you all the non-public members (hence the name). This
includes internal members.

The documentation neglects to include internal members in its list of what
constitutes non-public, but in practice, NonPublic gets you all the
non-public members.

--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/
Nov 16 '05 #2

(BindingFlags.Static | BindingFlags.NonPublic);
Returns all static internal, private and protected.

(BindingFlags.Static | BindingFlags.Public);
Returns only static public.

(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
Returns all static methods.

Substitute BindingFlags.Static with BindingFlags.Instance to return all
non-static methods.

Willy.

"TEK" <tr***************@hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
When using reflection, the Type.GetProperty method has the following
signature:
Type.GetProperty(String, BindingFlags)

The doc says:
a.. Specify BindingFlags.Public to include public properties in the
search.
a.. Specify BindingFlags.NonPublic to include non-public properties (that
is, private and protected properties) in the search.

But how the heck do I get access to the Internal methods???
Specifying BindingFlags.Public | BindingFlags.NonPublic causes the
internal methods to not be found.

Does anyone have any hint about what to do to get the internal methods as
well?

Regards, TEK

Nov 16 '05 #3
TEK
Hello

Thanks for the reply.

Futher investigation shows that the problem only shows itself if the
internal member is declared in a base class.

Meaning that using:

And having a base class that declares a property as internal causes the call
below (not actual code) to return null instead of the property.

myType.GetProperty(myObject, "MyProperty", BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Instance)

Changing the property to public or making the call directly on the base
class type makes it return the property.

(I have not tested changing the type to protected or private)

Is this a bug?

Regards, TEK

"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> skrev i melding
news:<u3**************@TK2MSFTNGP10.phx.gbl>...
"TEK" <tr***************@hotmail.com> wrote:
But how the heck do I get access to the Internal methods??? Specifying BindingFlags.Public | BindingFlags.NonPublic causes the internal methods to not be found.

NonPublic gets you all the non-public members (hence the name). This includes internal members. The documentation neglects to include internal members in its list of what constitutes non-public, but in practice, NonPublic gets you all the non-public members. -- Ian Griffiths - http://www.interact-sw.co.uk/iangblog/ DevelopMentor - http://www.develop.com/

Nov 16 '05 #4
"TEK" wrote:

having a base class that declares a property as internal causes the call
below (not actual code) to return null instead of the property.

myType.GetProperty(myObject, "MyProperty", BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Instance)

Is this a bug?


Sure looks that way.

Particularly since one the Beta of V2.0 of the .NET Framework it behaves as
you'd expect.

I'm using this:

public class Base
{
internal int BaseInternProp { get { return 42; } }
protected int BaseProtProp { get { return 42; } }
}
public class Foo : Base
{
internal int InternProp { get { return 42; } }
protected int ProtProp { get { return 42; } }
}

and this:

Type t = typeof(Foo);
foreach (MemberInfo fi in t.GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic))
{
Console.WriteLine(fi.Name);
}
Output from VS.NET 2005 Beta 1:

InternProp
ProtProp
BaseInternProp
BaseProtProp

(i.e. what you'd expect.) Output from V1.1 of .NET (i.e. current version):

InternProp
ProtProp
BaseProtProp

Of the two, the first looks like right and the second looks wrong to me.

As far as I can tell this problem only applies to properties. If you use
fields, it all appears to work as you'd expect on both versions of .NET.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/
Nov 16 '05 #5
TEK
Hay again

Thanks a lot for the input.
Then I assume it's a bug and uses a workaround instead.
If I get time I'll see if I'll convert my methods to be using Field instead.

Quite annoying!

Best regards, TEK

"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> skrev i melding
news:ug**************@TK2MSFTNGP12.phx.gbl...
"TEK" wrote:

having a base class that declares a property as internal causes the call
below (not actual code) to return null instead of the property.

myType.GetProperty(myObject, "MyProperty", BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Instance)

Is this a bug?


Sure looks that way.

Particularly since one the Beta of V2.0 of the .NET Framework it behaves
as you'd expect.

I'm using this:

public class Base
{
internal int BaseInternProp { get { return 42; } }
protected int BaseProtProp { get { return 42; } }
}
public class Foo : Base
{
internal int InternProp { get { return 42; } }
protected int ProtProp { get { return 42; } }
}

and this:

Type t = typeof(Foo);
foreach (MemberInfo fi in t.GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic))
{
Console.WriteLine(fi.Name);
}
Output from VS.NET 2005 Beta 1:

InternProp
ProtProp
BaseInternProp
BaseProtProp

(i.e. what you'd expect.) Output from V1.1 of .NET (i.e. current
version):

InternProp
ProtProp
BaseProtProp

Of the two, the first looks like right and the second looks wrong to me.

As far as I can tell this problem only applies to properties. If you use
fields, it all appears to work as you'd expect on both versions of .NET.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

Nov 16 '05 #6

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

Similar topics

2
21227
by: Hari Om | last post by:
Cannot connect as Internal Hello, I am using IBM AIX 5.1L box for Oracle 9.2.0.1. I cannot connect as internal to my DB INstance - wonder why? Here is what is do:...
1
2822
by: Christina Androne | last post by:
Hello! Did System.Reflection.BindingFlags.LookupAll flag ever existed? If yes, what flag/ combination of flags is/are replacing it now?? Thanks in advance, Christina Androne
1
13159
by: Ayende Rahien | last post by:
reparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error (0xc0000005 at address 53168B12): likely culprit is 'BIND'. An internal...
5
11733
by: Urs | last post by:
Hi all, I'm rather new to C# so please forgive my ignorance. I'd like to list the public, non-inherited methods of a class. I thought MethodInfo mi = typeof(string).GetMethods(...
2
6787
by: Chien Lau | last post by:
I frequently define internal UserControl-derived classes in my WinForms apps: internal class MyUserControl:UserControl{ ... } I'll often need to embed these controls in a Form, whose class...
3
4810
by: Trewq | last post by:
Hello you, Problem is that Type.GetFields does not return InnerList from a class that inherits from CollectionBase. I have a class: Public Class MyCollection Inherits...
2
5498
by: mike_li | last post by:
On Window 2000 Professional Server DB2 UDB Level: DB2 code release "SQL07029" with level identifie "030A0105" and informational tokens "DB2 v7.1.0.98", "n040510" and "WR21337". In the...
2
1766
by: billsahiker | last post by:
How can I use reflection to inspect any assembly and get only the methods written by the developers of the assembly, not all the built- in methods. When I use GetMethods on the Module, it returns...
2
2193
by: Martin Eckart | last post by:
Hi guys, I have a class which contains ~ 200 properties. Out of those 200 properties I need to access 10 (which I know beforehand already) via reflection in another class. Currently I am doing...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.