C# Late Binding for Parameterized Property

Posted by optim on Stack Overflow See other posts from Stack Overflow or by optim
Published on 2010-05-10T20:07:17Z Indexed on 2010/05/10 21:44 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|

I'm trying to use late binding to connect to a COM automation API provided by a program called Amibroker, using a C# WinForms project. So far I've been able to connect to everything in the API except one item, which I believe to be a "parameterized property" based on extensive Googling.

Here's what the API specification looks like according to the docs (Full version here: http://www.amibroker.com/guide/objects.html):

Property Filter(ByVal nType  As Integer, ByVal pszCategory As String) As Long [r/w]

A javascript snippet to update the value looks like this:

AB = new ActiveXObject("Broker.Application");
AA = AB.Analysis;
AA.Filter( 0, "market" ) = 0;

Using the following C# late-binding code, I can get the value of the property, but I can't for the life of me figure out how to set the value:

object[] parameter = new object[2];
parameter[0] = Number;
parameter[1] = Type;
object filters = _analysis.GetType().InvokeMember("Filter", BindingFlags.GetProperty, null, _analysis, parameter);

So far I have tried:

  • using BindingFlags.SetProperty, BindingFlags.SetField
  • casting the returned object to a PropertyInfo object and trying to update the value using it
  • adding extra object containing the value to the parameters object
  • various other things as last-ditch efforts

From what I can see, this should be straight-forward, but I'm finding the late binding in C# to be cumbersome at best. The property looks like a method call to me, which is what is throwing me off. How does one assign a value to a method, and what would the prototype for late-binding C# code look like for it?

Hopefully that explains it well enough, but feel free to ask if I've left anything unclear. Thanks in advance for any help!

Daniel

© Stack Overflow or respective owner

Related posts about c#

Related posts about com