473,881 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Reflecti on;

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

BindingFlags flags = BindingFlags.In stance | BindingFlags.No nPublic ;

B b = new B();

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

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

MethodInfo notHidden = t.GetMethod("dM ethod", flags);
if (notHidden != null)
Console.WriteLi ne("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 1110

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

Similar topics

8
2560
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 accesible from whichever types inside the assembly or from derived classes included those outside the assembly. The IL has a provision for the "family AND assembly" accesibility level, that is, a member is accesible from derived classes belonging to...
1
1647
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 wanted to be clever and hook up to the events that are already defined in the XmlDocument class (i.e. NodeChanged, NodeInserted). I had presumed I would simply be able to override them, however I cannot
4
1642
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 handful of inherited classes. The static method calls the ctor of the appropriate inherited class and returns it as type IBaseClass. There are no new methods or properties in the inherited classes and public clients never need to know which...
9
2353
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 readonly field cannot be assigned to (except in a constructor or a variable initializer).' Any ideas would be apreciated, though I was hoping I wouldn't have to use a property. Reuben.
4
4656
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 to a specific XSD that is defined. Right now when I declare XmlDocument as my argument, it puts the old xml:any type in. How do I change that to reflect the XSD that I'm looking for? Thanks for any Help!
6
1773
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 the individual elements in an array of ImageList's could be identified by the ID, thereby allowing re-ordering the array without harm. A person could identify by index into the array, but that would not be preserved by re-ordering (and re-ordering...
1
1231
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 interface I2 : I
5
1285
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) superclass's operators. How can that be when operators are always static? Is it a special case? It's handy, sure, but doesn't it "break" the language somehow? Or isn't this actually inheritance at play here?
9
2174
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) Hide.dll methods and data I want to remain hidden I have a DLL, Hide.dll, that contains methods that I want to handle for
0
9926
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10716
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...
1
10812
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7953
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
7108
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
5780
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
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
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.