I’m writing a library for C#. I’m wondering if it’s possible to only have methods/fields available if the library is being used in a C# project, and if it is being used in another .NET language like Visual Basic the methods won’t be accessible. The reason for this is because there are some functions/fields that are only useful for unsafe-code, and it would be a little bit silly if they were available for Visual Basic if they served no purpose.
Is it possible to only have certain classes/methods/fields available depending on the language of which they are being utilized in? If not I could easily just have 2 separate assemblies available for download, i.e. one for C# and one for VB.Net. Or I could simply include the extra methods regardless (but I would like to prevent confusion with those who aren’t familiar with pointers and unsafe code, just to keep users from messing around with unsafe methods and accidentally doing something silly, but I guess it really doesn’t matter!).
Thanks!
No.
Use abstraction. Create an assembly with interfaces/base classes and give some consumers that assembly together with another with safe implementations and other consumers the base assembly together with another that exposes advanced functionality.
Alternatively, you could use one assembly with internal methods and use the InternalsVisibleToAttribute if you know which “advanced” assemblies will be consuming it.