【发布时间】:2012-06-07 00:30:39
【问题描述】:
首先,是的,我看过这些帖子:
Is there an easy way in C# to have conditional compilation symbols based on OS version
Conditional compilation depending on the framework version in C#
但他们没有瞄准我正在寻找的方向。
我正在寻找的具体是 variable _type_ 资格(通过操作系统版本):
public struct REPASTESPECIAL
{
UInt32 dwAspect;
#if WINVER >= 6.0
UIntPtr dwParam;
#else
UInt32 dwParam;
#endif
}
我不想回到这样的状态:
public struct REPASTESPECIAL<T>
{
UInt32 dwAspect;
T dwParam;
}
// return type by OS version
public static Type GetRePasteSpecial_ParamType()
{
if (Environment.OSVersion.Version.Major >= 5) return typeof(IntPtr);
else return typeof(UInt32);
}
...因为当我希望 dwParam 仅成为 IntPtr 或 UInt32 对象时,这将允许程序员使用任何类型 T 的对象,但如果我必须这样做,并将其作为其他人的参考一样的。
【问题讨论】:
-
您的第一个示例似乎是 Visual Studio 2010 中的犹太教。您遇到错误了吗?
标签: c# variables struct operating-system conditional-compilation