如何克服两个命名空间中的相同类型,System.Linq.Expressions.Expression ?(How to overcome same type in two namespaces, S

编程入门 行业动态 更新时间:2024-10-19 16:31:35
如何克服两个命名空间中的相同类型,System.Linq.Expressions.Expression ?(How to overcome same type in two namespaces, System.Linq.Expressions.Expression?)

我在我的应用程序中定义了一些表达式变量,需要引用Microsoft.Scripting.Core。 该程序集包含与主要.Net框架中的System.Core程序集相同的名称空间。

我想使用System.Core程序集的定义,因为它是稳定的,而Microsoft.Scripting.Core是alpha。

如何告诉我的应用程序优先使用System.Core中的System.Linq.Expressions命名空间而不是Microsoft.Scripting.Core,但是仍然能够保留对它的引用?

I am defining some Expression variables in my app and need to have a reference to Microsoft.Scripting.Core. That assembly includes the same namespace as the System.Core assembly from the main .Net framework.

I want to use the defintions from the System.Core assembly as it's stable whereas the Microsoft.Scripting.Core is alpha.

How do I tell my app to preference the System.Linq.Expressions namespace in System.Core instead of Microsoft.Scripting.Core but still be able to keep the reference to it?

最满意答案

正如马克所说,这不是非常好 - 但外部别名是要走的路。

在解决方案资源管理器的“参考”部分中,选择System.Core程序集,转到属性。 将“Aliases”属性更改为包含“syscore”,例如

Aliases: global,syscore

然后,在要使用System.Linq.Expressions的任何文件的顶部,键入:

extern alias syscore; using syscore::System.Linq.Expressions;

这是丑陋的,但至少有可能:)

作为一个告诫,在扩展方法和外部别名方面,我已经看到了一些问题, 正如这个问题所描述的那样 。

As Marc says, it's not terribly nice - but extern aliases are the way to go.

In the "References" part of solution explorer, select the System.Core assembly, go to properties. Change the "Aliases" property to include "syscore", e.g.

Aliases: global,syscore

Then at the top of any file where you want to use System.Linq.Expressions, type:

extern alias syscore; using syscore::System.Linq.Expressions;

It's ugly, but at least it's possible :)

As a caveat, I've seen some problems when it comes to extension methods and extern aliases, as described in this question.

更多推荐

本文发布于:2023-07-22 09:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   类型   空间   System   Linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!