473,671 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BindingFlags.In ternal, where is that?

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

The doc says:
a.. Specify BindingFlags.Pu blic to include public properties in the search.
a.. Specify BindingFlags.No nPublic 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.Pu blic | BindingFlags.No nPublic 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 14830
"TEK" <tr************ ***@hotmail.com > wrote:
But how the heck do I get access to the Internal methods???
Specifying BindingFlags.Pu blic | BindingFlags.No nPublic 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.S tatic | BindingFlags.No nPublic);
Returns all static internal, private and protected.

(BindingFlags.S tatic | BindingFlags.Pu blic);
Returns only static public.

(BindingFlags.S tatic | BindingFlags.Pu blic | BindingFlags.No nPublic);
Returns all static methods.

Substitute BindingFlags.St atic with BindingFlags.In stance to return all
non-static methods.

Willy.

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

The doc says:
a.. Specify BindingFlags.Pu blic to include public properties in the
search.
a.. Specify BindingFlags.No nPublic 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.Pu blic | BindingFlags.No nPublic 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.GetPrope rty(myObject, "MyProperty ", BindingFlags.No nPublic |
BindingFlags.Pu blic | BindingFlags.In stance)

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******* *******@TK2MSFT NGP10.phx.gbl>. ..
"TEK" <tr************ ***@hotmail.com > wrote:
But how the heck do I get access to the Internal methods??? Specifying BindingFlags.Pu blic | BindingFlags.No nPublic 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.GetPrope rty(myObject, "MyProperty ", BindingFlags.No nPublic |
BindingFlags.Pu blic | BindingFlags.In stance)

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.I nstance |
BindingFlags.No nPublic))
{
Console.WriteLi ne(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******** ******@TK2MSFTN GP12.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.GetPrope rty(myObject, "MyProperty ", BindingFlags.No nPublic |
BindingFlags.Pu blic | BindingFlags.In stance)

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.I nstance |
BindingFlags.No nPublic))
{
Console.WriteLi ne(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
21237
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: ------------------------------------------------------------------- $export ORACLE_SID=GATES
1
2833
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
13218
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 error has occurred in the compiler. To work around this problem,
5
11757
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( BindingFlags.Public | BindingFlags.DeclaredOnly); would do just that, but no methods at all are returned. Going on, I tried typeof(string).GetMethods(BindingFlags.Public),
2
6799
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 is contained in the same assembly as the control. As far as I know, the only way to do this using the designer is to add the UserControl-derived object
3
4823
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 System.Collections.CollectionBase ...
2
5514
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 db2diag.log, ---------------------------------------------------- 2005-12-20-10.05.43.278000 Instance:MC Node:000
2
1772
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 all the built-in methods, so for a Form, I get get_autosize, get_autoscroll, which I do not want. How can I filter those out? I tried bindingflags, but any combination of bindingflags returns an empty methodinfo collection, e.g.,...
2
2202
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 the following with my context object which represents the class containing the 200 properties: Type t = context.GetType(); foreach (PropertyInfo prop in t.GetProperties()
0
8392
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.