[英]Why can't I declare a using statement for a namespace, but can directly declare the namespace before the type?
I'm wondering if someone has seen this scenario before or has any suggestions to what might be causing it. 我想知道是否有人以前见过这种情况,或者对可能导致这种情况的任何建议。 I have a custom class called
Dashboard
that exists inside a project called Dashboard.Data.Client
. 我有一个名为
Dashboard
的自定义类,该类存在于名为Dashboard.Data.Client
的项目中。 Within that same project, if I try to reference the class's namespace such as: 在同一项目中,如果我尝试引用该类的名称空间,例如:
using Alliance.Dashboard.Data.Client.Models;
then I cannot use the type Dashboard
. 那么我不能使用
Dashboard
类型。 However, anywhere I need to use Dashboard
, I can type out the fully qualified name and it works fine. 但是,在需要使用
Dashboard
任何地方,我都可以键入完全限定的名称,并且可以正常使用。 Example: 例:
Alliance.Dashboard.Data.Client.Models.Dashboard myDashboard = new Alliance.Dashboard.Data.Client.Models.Dashboard();
A few notes I'm sure you will be wondering: 我确信您会想知道一些注意事项:
If I just type Dashboard
in a class, and then try to resolve it, the option isn't available. 如果我只是在课堂上键入
Dashboard
,然后尝试解决它,则该选项不可用。
I have seen this issue before if there are conflicting namespaces. 如果存在冲突的命名空间,我以前已经看到过此问题。 In such case, a fully qualified name must be given.
在这种情况下,必须提供完全限定的名称。 That is not the case here.
这里情况不同。 There is no conflicting namespaces.
没有冲突的名称空间。
Other classes resolve just fine within this project. 在本项目中,其他类也可以很好地解决。 As a matter of fact, here is a scenario: from
IDashboardRepository
this problem exists trying to declare Dashboard
just as I described. 实际上,这是一个场景:从
IDashboardRepository
开始,正如我所描述的,尝试声明Dashboard
存在此问题。 IDashboardRepository
is in the same project but in a different namespace: Alliance.Dashboard.Data.Client.Interfaces
. IDashboardRepository
位于同一项目中,但位于不同的命名空间中: Alliance.Dashboard.Data.Client.Interfaces
。 However, the reverse works fine. 但是,反向工作正常。 In other words, I can use the interface namespace as a using statement within
Dashboard
, but not Dashboard
inside the interface without the fully qualified name. 换句话说,我可以在
Dashboard
中将接口名称空间用作using语句,但在没有完全限定名称的接口中,不能将Dashboard
用作接口。
For reference, here is the code for my Dashboard
class: 作为参考,这是我的
Dashboard
类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Alliance.Dashboard.Data.Client.Models
{
public class Dashboard
{
public System.Guid DashboardID { get; set; }
public string DashboardName { get; set; }
public byte[] Instance { get; set; }
public bool IsDeleted { get; set; }
public byte[] Concurrency { get; set; }
}
}
Well, I feel pretty stupid on this one. 好吧,我对此感到非常愚蠢。 Simply put, the namespace and class name are the same.
简而言之,名称空间和类名称相同。 The compiler thinks that I have entered the beginning of the namespace directory instead of the class name.
编译器认为我已经输入了名称空间目录的开头,而不是类名。 Thanks again for taking time to help another knuckle head.
再次感谢您抽出宝贵时间来帮助另一个转向节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.