In the .Net framework, I am under the impression that you can write a library in one language (say C++), then import that code and use that library cleanly in some other C# project (assuming they both target the same framework version).
However, I don't understand how this works when there could be methods defined in C++ that wouldn't make sense in some other language like C# or VB.net, such as a method parameter that takes a struct that isn't a pointer.
Perhaps my example doesn't hold up due to my limited knowledge of all the CLR languages, but I have to assume there are things that one language can do that another can't -- and I don't get how these discrepancies are dealt with.
It is perfectly well possible to create a method, class, struct, type or whatever in one .NET language that cannot be called by another directly. Calling it indirectly (by means of reflection, for instance) is always possible.
I.e., if you look at any compiled C# project, you'll see that the compiled code contains some code with weird names and characters in it, usually for supporting generics. One such name is <Module> (including the brackets), which, even if it were made a public method, can never be called from C# directly.
Language designers that decide to compile for the CLR must support a minimal subset for public types. This is referred to as CLS Compliance and is about a common naming convention, no public pointers or public unsafe members or classes, no names that only differ by case, no public static fields and some more rules. When they obey to this rule it is guaranteed that any other .NET language can call your methods. They know how to do this, because the rules for this are well laid out and documented.
You can even create non-compliant C# code. It will (usually) compile, but it is not guaranteed that all compliant languages can call your method. The same is true for most other languages, including C++.NET. It is a Microsoft Design Guideline to mark your assemblies as CLSCompliant by default (whether it's written in C++, VB, Ruby doesn't matter).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With