C#4 编译器中的奇怪错误?别名命名空间变得混乱
这是我的问题,
我使用命名空间来消除工厂类的歧义,该工厂类从实体框架实体对象(POCO 工厂,..如果有意义的话!)创建域对象。你可以说我很老式,但我喜欢这种方式 :-)
我正在使用的命名空间就是这样的别名 -
using Entities = DataAccess.Models.AccessControl;
using Cases = DomainModel.BusinessObjects.Implimentations.Cases;
现在,DomainModel.BusinessObjects.Implementations.Cases
命名空间到目前为止只有一种类型,称为案例类型
。然而,当我正在研究另一种使用 CaseType
类的类型时,我注意到当我“点”到 Cases
别名时,它指向我的 CaseType
中一个完全不同的命名空间。 code>DataAccess 程序集,并在智能感知中为我提供了 CaseTypeFactory
。
所以我检查了 CaseType
和 CaseTypeFactory
类,它们命名空间正确。天哪,这是怎么回事?这件事我实在是没法解决。
这是 CaseType
和 CaseTypeFactory
的代码(如果有帮助的话)。
CaseTypeFactory
using Domain = DomainModel.BusinessObjects.Implimentations.Cases;
using Entities = DataAccess.Models.AccessControl;
using Interfaces.DataAccess;
namespace DataAccess.Factories.Cases
{
public class CaseTypeFactory :
IEntityPOCOFactory<Domain.CaseType, Entities.CaseType>
{
#region IEntityPOCOFactory<CaseType,CaseType> Members
public Domain.CaseType CreatePOCO(Entities.CaseType entity)
{
return new Domain.CaseType(entity.Id, entity.Name, entity.LastChanged);
}
public IList<Domain.CaseType> CreatePOCOs(
IEnumerable<Entities.CaseType> entities)
{
var toReturn = new List<Domain.CaseType>();
foreach (var entity in entities)
{
toReturn.Add(CreatePOCO(entity));
}
return toReturn;
}
#endregion
}
}
CaseType
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.BusinessObjects.Base;
namespace DomainModel.BusinessObjects.Implimentations.Cases
{
public class CaseType : NamedNumberedAndVersioned
{
public CaseType(string name, DateTime lastChanged)
: this(0, name, lastChanged) { }
public CaseType(int id, string name, DateTime lastChanged)
: base(id, name, lastChanged) { }
public void Update(string name)
{
this.Name = name;
}
}
}
可能值得一提的是,我正在使用 .Net 4.0 / VS2010
任何帮助将不胜感激。 提前致谢。
Here's my issue,
I'm using a namespace to remove ambiguity from a factory class which is creating domain objects from entity framework entity objects (a POCO factory,.. if that makes sense!). Call me old fashioned but I like things this way :-)
The namespaces I'm working with are aliased as such -
using Entities = DataAccess.Models.AccessControl;
using Cases = DomainModel.BusinessObjects.Implimentations.Cases;
Now, the DomainModel.BusinessObjects.Implimentations.Cases
namespace only has one type so far called CaseType
. However whilst I was working on another type which consumes the CaseType
class I noticed that when I 'dot' into the Cases
alias, it points to a totally different namespace in my DataAccess
assembly and gives me the CaseTypeFactory
in intellisense.
So I checked the CaseType
and CaseTypeFactory
classes and they are namespaced correctly. What in god's name is going on? I really can't work this one out.
Here's the code for the CaseType
and CaseTypeFactory
if it helps.
CaseTypeFactory
using Domain = DomainModel.BusinessObjects.Implimentations.Cases;
using Entities = DataAccess.Models.AccessControl;
using Interfaces.DataAccess;
namespace DataAccess.Factories.Cases
{
public class CaseTypeFactory :
IEntityPOCOFactory<Domain.CaseType, Entities.CaseType>
{
#region IEntityPOCOFactory<CaseType,CaseType> Members
public Domain.CaseType CreatePOCO(Entities.CaseType entity)
{
return new Domain.CaseType(entity.Id, entity.Name, entity.LastChanged);
}
public IList<Domain.CaseType> CreatePOCOs(
IEnumerable<Entities.CaseType> entities)
{
var toReturn = new List<Domain.CaseType>();
foreach (var entity in entities)
{
toReturn.Add(CreatePOCO(entity));
}
return toReturn;
}
#endregion
}
}
CaseType
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.BusinessObjects.Base;
namespace DomainModel.BusinessObjects.Implimentations.Cases
{
public class CaseType : NamedNumberedAndVersioned
{
public CaseType(string name, DateTime lastChanged)
: this(0, name, lastChanged) { }
public CaseType(int id, string name, DateTime lastChanged)
: base(id, name, lastChanged) { }
public void Update(string name)
{
this.Name = name;
}
}
}
It's probably worth mentioning I'm working with .Net 4.0 / VS2010
Any help would be massively appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在
DataAccess.Factories
命名空间中编写的代码吗?如果是这样,那么Cases
确实会首先解析为DataAccess.Factories.Cases
。两个选项:
使用一个不是另一个命名空间的名称的别名,例如
使用
::
而不是。< /code> 强制它使用别名:
我个人会选择第一个选项以使事情更清晰。 ..或者尝试避免要求名称空间别名开头。
Is the code you're writing in the
DataAccess.Factories
namespace? If so, thenCases
will indeed resolve toDataAccess.Factories.Cases
first.Two options:
Use an alias which isn't also the name of another namespace, e.g.
Use
::
instead of.
to force it to use the alias:I'd personally go for the first option to make things clearer... or try to avoid requiring namespace aliases to start with.