从使用的名称空间中排除类 [英] exclude a class from a used namespace

查看:65
本文介绍了从使用的名称空间中排除类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有C#文件的第一个语句是"使用系统; ".现在,在框架版本4中,该名称空间包含一个名为"Action"的类.这也是在常规使用的命名空间中我自己的代码中的类的名称.现在当然有冲突.当然,我可以通过使用显式的"MyNamespace.Action"解决此冲突,而以前我从未使用过"Action".这是几百甚至几千行.或者我不能使用System名称空间,这当然会导致许多其他问题.我想写类似使用System而不是System.Action"的东西,但是我找不到执行此操作的语句.有什么想法吗?

The first statement of all my C# files is "using System;". Now with framework version 4 this namespace contains a class called "Action". This is also the name for a class im my own code in a regularly used namespace. Now there is of course a conflict. Ofcourse I can resolve this conflict by using explicit "MyNamespace.Action" where ever I was using "Action" before. This are several hundreds if not thousands of lines. Or I could not use the System namespace, which of course leads to many other problems. I would like to write something like "using System but not System.Action", but I cannot find a statement to do this. Any ideas?

推荐答案

不,你不能.

但是您可以使用Action = MyNamespace.Action 添加.不过,这对于新开发人员来说会非常令人困惑,因为Action自3.5起就是.net的基本组成部分,因此我强烈建议您重命名您的类.

But you can add using Action = MyNamespace.Action. This will be highly confusing for new developers, though, as Action is a fundamental part of .net since 3.5 so I strongly suggest you rename your class.

这篇关于从使用的名称空间中排除类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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