How to support optional parameters for COM

12/09/2007 - 10:48 von Norbert Pürringer | Report spam
Hello,

I want to provide a C# class, which can be called as COM object from
outside (COM interop).

My problem is, that C# does not support optional parameters. But in
the world of COM, optional parameters are allowed and are often used.
Is it possible to define a function parameter as optional for COM?

Regards,
Norbert
 

Lesen sie die antworten

#1 Frank Dzaebel
12/09/2007 - 11:54 | Warnen spam
Hallo Norbert,

I want to provide a C# class, which can be called
as COM object from outside (COM interop).
My problem is, that C# does not support optional parameters. But in
the world of COM, optional parameters are allowed and are often used.
Is it possible to define a function parameter as optional for COM?



Wir sprechen hier Deutsch!
Ich nutze gerne das params Schlüsselwort
in Verbindung mit BindingFlags.OptionalParamBinding:

private object Call(object target, string methodName,
params object[] parameters)
{
return target.GetType().InvokeMember(methodName,
BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding,
null, target, parameters);
}


ciao Frank
Dipl.Inf. Frank Dzaebel [MCP/MVP C#]
http://Dzaebel.NET

Ähnliche fragen