Question

I'm currently building a c++/cli interop library. The library will be consumed by c# and vb.net applications, and I would like to make use of .Net 4 dynamic typing. I have a configuration module that uses dynamic member access to refer to configuration keys, this works fine in c# but is giving me trouble in c++/cli (not entirely unexpected) Is there any way to use this library in C++/CLI (e.g. by invoking TryGetMember() directly or something)? If the C++/CLI library then passes the dynamic configuration to a derived class written in C#, will the C# still be able to use dynamic member access? Note that the base class is defined in c++/cli, so I wouldn't be able to use the dynamic keyword. (or would I?)

Was it helpful?

Solution

There is an open source library, ImpromptuInterface (found via nuget) that simplifies the api's used by the c# compiler when the dynamic keyword is involved, I'd assume it works in c++/cli, since they are just static c# functions. I know it works in F# that also doesn't have DLR support.

Here is a list of dynamic invoking it can do.

OTHER TIPS

C#/VB dynamic types are translated by the compiler into ordinary types and method calls. The generated IL is somewhat complex, but not special in any way. You can definitely write C++/CLI code that generates similar IL.

Perhaps the easiest way to write the C++/CLI code would be to write the code that uses the dynamic types in C#, and then use Reflector to decompile the assembly into C++/CLI.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top