473,320 Members | 1,993 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.

repost - Reflection and Inheritance

My original posting (Dec 12, this group) is copied below, but it boils down
to a simple question first:
does an inherited class prevent certain internal properties (inherited from
an ancestor class) from being visible to GetType().GetMethod()?

And can I call GetMethod from the context of the ancestor?

Basically, can I get the following to work?

----------------------------------------------------------------------------------

I haven't played much with Reflection before, so I'm hoping I'm missing
something simple with this problem I'm having.

Trying to follow the online examples for resizing a DataGrid row height, and
the following is the snippet:

------
MethodInfo mi = dataGrid.GetType().GetMethod( "get_DataGridRows",
BindingFlags.FlattenHierarchy |
BindingFlags.IgnoreCase |
BindingFlags.Instance |
BindingFlags.NonPublic);
Array dataGridArray = (Array) mi.Invoke( dataGrid, null );
------

But, my dataGrid in this case is an overridden System.Windows.Forms.DataGrid
class, and GetMethod does not find my "get_DataGridRows" for my inherrited
class. mi is null for the above execution. I've tried seeing if I can cast
the type to the lower one, but I must be too tired to figure it out, so
hopefully someone here can assist me.

Thanks.


Dec 14 '05 #1
4 2345
Hi John,

Because I already answered your prev post but it did not help, I try it
again.
It was my mistake that did not take your sentence "But, my dataGrid in
this case is an overridden System.Windows.Forms.DataGrid class" into
account.

Because it is "internal", not "protected", property, and your assembly
is different from System.Windows.Form.dll, the answer is no.

You can try this snippet instead:
MethodInfo mi = dataGrid.GetType().BaseType.GetMethod(
"get_DataGridRows",
BindingFlags.Instance | BindingFlags.NonPublic);
Array dataGridArray = (Array) mi.Invoke( dataGrid, null );

Note I add "BaseType" after GetType() because your data grid is
directly derived from System.Windows.Forms.DataGrid. If not, you can
call continuously calling BaseType until you get to
System.Windows.Forms.DataGrid, like this:

Type t = dataGrid.GetType().BaseType;
while (t != typeof(DataGrid))
{
t = t.BaseType;
}
MethodInfo mi = t.GetMethod("get_DataGridRows",
BindingFlags.Instance | BindingFlags.NonPublic);
Array dataGridArray = (Array) mi.Invoke( dataGrid, null );

Hope this time I can help,
Let me know if it still does not :)
Regards,
Thi

Dec 14 '05 #2
Couldn't you just shorten this to

typeof(Windows.Forms.DataGrid).GetMethod(...) etc

?

Marc
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hi John,

Because I already answered your prev post but it did not help, I try it
again.
It was my mistake that did not take your sentence "But, my dataGrid in
this case is an overridden System.Windows.Forms.DataGrid class" into
account.

Because it is "internal", not "protected", property, and your assembly
is different from System.Windows.Form.dll, the answer is no.

You can try this snippet instead:
MethodInfo mi = dataGrid.GetType().BaseType.GetMethod(
"get_DataGridRows",
BindingFlags.Instance | BindingFlags.NonPublic);
Array dataGridArray = (Array) mi.Invoke( dataGrid, null );

Note I add "BaseType" after GetType() because your data grid is
directly derived from System.Windows.Forms.DataGrid. If not, you can
call continuously calling BaseType until you get to
System.Windows.Forms.DataGrid, like this:

Type t = dataGrid.GetType().BaseType;
while (t != typeof(DataGrid))
{
t = t.BaseType;
}
MethodInfo mi = t.GetMethod("get_DataGridRows",
BindingFlags.Instance | BindingFlags.NonPublic);
Array dataGridArray = (Array) mi.Invoke( dataGrid, null );

Hope this time I can help,
Let me know if it still does not :)
Regards,
Thi

Dec 14 '05 #3
uh, yes, right.

Dec 14 '05 #4
ok... yeah, I figured it was an easy one, just didn't see it. thanks a lot.

I had tried to cast it: DataGrid g = myGrid as DataGrid and then going
through it, but I guess no matter the casted type, getType() seems to return
the most "recent" type, for lack of a better term, which is what I would
expect anyways.

As an aside, Thi, sorry about the repost. I can't believe how busy this
group is getting. It hasn't been that long and already my (original) post
is way down the list. I figured you wouldn't get the chance to see my
reply. :)
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
uh, yes, right.

Dec 14 '05 #5

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

Similar topics

1
by: P Vinodh Kumar | last post by:
Reposting, please give your ideas/suggestions/comments. I am reading Lippman's Inside C++ object model. I feel lonely because the Microsoft C++ compiler which I use does not provide me an...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
0
by: aegis | last post by:
Hi All, Im developing a web service in C# that Im running into a few problems with. Essentially I am trying to move a custom class (which contains an array of objects) over the WS to the client....
4
by: Bob | last post by:
If you rename a type at design time, the the task list shows what code broke, which happens to be a very nice list of dependant classes and methods. Is there any way to produce such dependency...
8
by: Rlrcstr | last post by:
If I have some code behind a form and I want to be able to pass an object to it... any of several user defined classes that I have... and then display the values in the member variables of the...
7
by: guy | last post by:
just discovered that the combination of visual inheritance and reflection can eliminate most of the databinding i would normally do, providing the design is right! and its only taken me 4 years...
4
by: Egbert Nierop \(MVP for IIS\) | last post by:
Hi, I have a CWindowImpl derived class , see below at ***, that needs to subclass simple controls like textboxes. like this...: m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd); ...
11
by: David Veeneman | last post by:
I need to get a parent's private variable from within a control. Here's what I'm doing: I have a control that I want to be able to detect the presence of a particular (System.ComponentModel)...
10
by: Rotsey | last post by:
Hi, I have a class that exist in my UI assembly that inherits from a class in a referenced assembly like this. class EmployeesDC { private string mstrEmployeeNumber; etc
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
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
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...

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.