在C/C++,你可以#包括其中包含枚舉定義一個cs文件。謹慎使用預處理指令的需要的C#和C之間的語法差異護理
例子:
#if CSharp
namespace MyNamespace.SharedEnumerations
{
public
#endif
enum MyFirstEnumeration
{
Autodetect = -1,
Windows2000,
WindowsXP,
WindowsVista,
OSX,
Linux,
// Count must be last entry - is used to determine number of items in the enum
Count
};
#if CSharp
public
#endif
enum MessageLevel
{
None, // Message is ignored
InfoMessage, // Message is written to info port.
InfoWarning, // Message is written to info port and warning is issued
Popup // User is alerted to the message
};
#if CSharp
public delegate void MessageEventHandler(MessageLevel level, string message);
}
#endif
在C#項目,設置條件編譯符號「CSHARP」,確保沒有這樣的預處理器定義存在在C/C++構建環境中。
請注意,這將只確保兩個部件在構建時同步。如果您混合使用不同版本的二進制文件,則保證失敗。
來源
2008-08-20 21:16:33
Rob