Gener4tor
Gener4tor

Reputation: 383

How to change the com-interface depended on the configuration in C#?

I got a com-interface in c# which looks like this:

[Serializable(), ClassInterface(ClassInterfaceType.None), ComVisible(true)]
[Guid("6e72b1ab-31ca-4852-9552-999999999999")]
[ProgId("SmartCard.SmartCardValidator")]
public class SmartCardValidator : ISmartCardValidator
{
    //...
}

For reasons I have to create 2 separate com-interfaces with different names and different guid out of the same class.

How can I change the ProgId and the Guid depending on the configuration I compile my project in?

In c++ I probably would do something with #ifdef but in C# I didnt find anything like that.

Upvotes: 0

Views: 32

Answers (1)

PMF
PMF

Reputation: 17338

In C# some limited preprocessor support exists as well. Instead of #ifdef you have to use #if <some condition> though.

So that would be

#if Configuration1
[Guid("6e72b1ab-31ca-4852-9552-999999999999")]
#else
[Guid("6e72b1ab-31ca-4852-9552-000000000000")]
#endif

The conditions can only be set from either the command line (or project file) or the first lines of the source file. That means that #define is only allowed before any other code line except for comments.

To define conditional symbols in the project, use "Project Properties -> Build -> Conditional compilation symbols"

Upvotes: 1

Related Questions