编译可与预处理程序指令一起使用的可移植类库时,是否有任何符号 [英] Are there any symbols when compiling a portable class library that can be used with preprocessor directives

查看:72
本文介绍了编译可与预处理程序指令一起使用的可移植类库时,是否有任何符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决方案中添加了一个可移植的类库,其中包含一个链接到所有项目的全局文件.此全局文件包含程序集级别的属性,例如版本,区域性和Com可见性.我要解决的问题是,诸如ComVisible之类的某些属性在PCL上下文中无效,因此是否有任何与#if一起使用的符号来防止在构建时将其包括在内?

I have added a portable class library to my solution in which has a global file that is linked to all the projects. This global file contains the assembly level attributes such as version, culture, and Com visibility. The problem I want to solve is that some attributes such as ComVisible are not valid in the context of a PCL so is there any symbol that used with #if to prevent that attribute for being included at build time?

推荐答案

我通过将stub/dummy属性类添加到模仿其FCL对应对象的紧凑框架项目中来解决了这个问题:

I overcame this issue by adding stub/dummy attribute classes to a compact framework project that mimic their FCL counterparts:

// Shared source file
[ComVisible(true)]
public class Foo
{
}

// Dummy class in portable project -- exists only to facilitate compilation of the shared source file
namespace System
{
    [AttributeUsage(AttributeTarget.Class)]
    public class ComVisibleAttribute : Attribute
    {
        public ComVisibleAttribue(bool visible)
        {
            // Dummy implementation
        }
    }
}

现在,共享源代码文件将在两个项目中编译,而无需对代码进行任何修改,也无需任何预处理程序指令.

Now the shared source code file will compile in both projects without any modification to the code, and without any preprocessor directives.

这篇关于编译可与预处理程序指令一起使用的可移植类库时,是否有任何符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆