473,395 Members | 1,554 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,395 software developers and data experts.

Reflection usage and InvokeMember vs. GetProperty with COM objects

A while back I've built a bunch of generic Reflection routines that
simplify
the process of access properties/fields and methods a bit easier by creating
wrappers around Property/Field/Method info members.

For example:

public const BindingFlags MemberAccess =

BindingFlags.Public | BindingFlags.NonPublic |

BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase;

public static object GetProperty(object Object,string Property)

{

return Object.GetType().GetProperty(Property,wwUtils.Memb erAccess |
BindingFlags.GetProperty).GetValue(Object,null);

}

There are versions for Get/Set and fields and properties as well as versions
that can nest references. All works fine with .Net types.

Today I tried to use this same code with a COM object and promptly it fell
flat. In the above example, GetProperty() fails to find the property.
However, the following works:

return Object.GetType().InvokeMember(Property,wwUtils.Mem berAccess |
BindingFlags.GetProperty,null,Object,null);

So now I'm wondering what is InvokeMember doing that is different here? I
seem to remember a discussion here that InvokeMember is a bit less
efficient, so if possible I'd like to avoid this.

Any ideas if it's possible to get the code to run with GetProperty et al.?

+++ Rick ---


--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web

Nov 16 '05 #1
0 1333

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

Similar topics

6
by: Laser Lu | last post by:
HI, all, I just want to invoke an internal method named 'ResolveClientUrl', which is defined in class System.Web.UI.Control, using an instance object of a type that derives from Control. Let's...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
0
by: Gemma M | last post by:
Hi, I have a C# program (code fragment below), which runs forever, processing incoming jobs. Part of this program launches a COM object. However, after a while I get : ...
5
by: Eric Goforth | last post by:
Hello, I have a generic subroutine that I pass an object and fieldname as arguments. The subroutine then uses reflection to search for the value of the fieldname. For example: 'Calling...
1
by: Jenny Fletcher | last post by:
I am trying to dynamically invoke a property of enumeration type but I can't find a way to get it to work. This is my code which works fine until I call InvokeMember and I get an ArgumentException....
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
0
by: Ralfeus | last post by:
Hi all. I'm developing a software for Windows Mobile 2003. I have such code: Control currControl = formControls ; if (elementType.GetProperty("Items") != null) { Type itemsType =...
6
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.