473,320 Members | 2,052 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,320 software developers and data experts.

Reflecting Inherited Internal Methods - Bug??

Hi,

I've been having an issue using reflection and custom attributes to create
objects on the fly. I was wondering if this was expected behaviour or a
known bug?
When using Type.GetMembers() or Type.GetMethods() on a sub class it will not
return the methods marked 'internal' on the parent class. After much
experimentation with BindingFlags, I discovered that in order for the methods
to become visible they needed to be 'virtual' too. The demostration below
shows the issue.

Thanks..Paul

using System;
using System.Reflection;

class TestReflection
{
[STAThread]
static void Main(string[] args)
{
Type t = typeof (B);

BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic ;

B b = new B();

MethodInfo hidden = t.GetMethod("cMethod", flags);
if (hidden != null)
Console.WriteLine("Found cMethod!"); // Never gets here :(

b.cMethod(); // ...but the method *IS* inherited because this line
succeeds!

MethodInfo notHidden = t.GetMethod("dMethod", flags);
if (notHidden != null)
Console.WriteLine("Found dMethod!"); // Curiously though it's happy with
the 'virtual' one...

b.dMethod();
}
}

public abstract class A
{
public abstract void aMethod();

public void bMethod()
{
int i = 1;
i++;
}

internal void cMethod()
{
int i = 2;
i++;
}

internal virtual void dMethod()
{
int i = 3;
i++;
}
}

public class B : A
{
public override void aMethod()
{
int i = 0;
i++;
}
}
Nov 17 '05 #1
0 1090

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

Similar topics

8
by: Carlos J. Quintero | last post by:
Hi, As you know the current keywords "protected internal" (C#) or "Protected Friend" (VB.Net) means "Protected Or internal" (C#) or "Protected Or Friend" (VB.Net), that is, the member is...
1
by: Robert | last post by:
Hi, I've inherited the XmlDocument class to include some custom methods that I want to use on a particular XML file. I need to know whether the document has changed since being loaded, and I...
4
by: Dan | last post by:
I have a need to make a set of classes that all share the same public methods, some implementation and some data. So, I made an abstract base (BaseClass) with an interface (IBaseClass) and a...
9
by: Reuben | last post by:
I have a field in an abstract class marked readonly. However, when I attempt to modify that field in the constructor of a class which inherits it, I get a compile-time error stating that 'A...
4
by: MattBell | last post by:
I've tried to search for an answer to this without much success, and I think it's probably a common thing to do: I have a web service I want to accept an XmlDocument as an argument which conforms...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
1
by: Hans Ruck | last post by:
I'm trying to detect the interfaces directly inherited by a class. I've tried to use the Type.GetInterfaces method but in a situation like this: public interface I { void f(); } public...
5
by: Shak | last post by:
Hi all. I was led to believe that static methods were not inherited by their subclasses (and since that makes sense, rightly so). However, a subclass I've written is using it's (abstract)...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.