基于@Bertrand Le Roy的回答/评论,请参阅下面的解决方案
原始问题:
不确定如何解释我的问题。
我在Orchard有一份Part记录:
[Display(Name = "Would you like us to call you to discuss the quote for your case?")]
public ContactClientList ContactClient
{
get { return Record.ContactClient; }
set { Record.ContactClient = value; }
}
public enum ContactClientList
{
ContactClient_Yes,
ContactClient_No
}
public class ContactClientDictionary
{
public static readonly Dictionary<ContactClientList, string> contactclientDictionary = new Dictionary<ContactClientList, string>
{
{ ContactClientList.ContactClient_No, "No, please do not contact me by telephone." },
{ ContactClientList.ContactClient_Yes, "Yes, please contact me as soon as possibly by telephone to discuss my Uncontested Divorce quote." },
};
static string ConvertContactClient(ContactClientList contactclientlist)
{
string name;
return (contactclientDictionary.TryGetValue(contactclientlist, out name))
? name : contactclientlist.ToString();
}
static void Main()
{
Console.WriteLine(ConvertContactClient(ContactClientList.ContactClient_Yes));
Console.WriteLine(ConvertContactClient(ContactClientList.ContactClient_No));
}
}
现在,我有一份零件记录:
public virtual ContactClientList ContactClient { get; set; }
我收到错误:
编译器错误消息:CS0246:类型或命名空间名称 找不到'ContactClientList'(你是否错过了使用 指令或程序集引用?)
有什么想法吗?
SOLUTION:
我拿出
public enum ContactClientList
{
ContactClient_Yes,
ContactClient_No
}
public class ContactClientDictionary
{
public static readonly Dictionary<ContactClientList, string> contactclientDictionary = new Dictionary<ContactClientList, string>
{
{ ContactClientList.ContactClient_No, "No, please do not contact me by telephone." },
{ ContactClientList.ContactClient_Yes, "Yes, please contact me as soon as possibly by telephone to discuss my Uncontested Divorce quote." },
};
static string ConvertContactClient(ContactClientList contactclientlist)
{
string name;
return (contactclientDictionary.TryGetValue(contactclientlist, out name))
? name : contactclientlist.ToString();
}
static void Main()
{
Console.WriteLine(ConvertContactClient(ContactClientList.ContactClient_Yes));
Console.WriteLine(ConvertContactClient(ContactClientList.ContactClient_No));
}
}
这
public class ModelNamePart : ContentPart<ModelNamePartRecord
{
public ContactClientList ContactClient
{
...
}
[TOOK OUT FROM HERE]
}
并且在ModelNamePartRecord.cs文件的末尾使它成为自己的类,但是必须更改类名(之后简单地添加“Enum”)并将其与ContentPartRecord关联(否则它将从表未映射的错误中抛出NHibernate关联) ):
public class ContactClientListEnum : ContentPartRecord
{
public enum ContactClientList
{
...
}
public class ContactClientDictionary
{
...
}
}
另外,在ModelNamePartRecord.cs文件中,我刚刚更新了类名:
public class ModelNamePartRecord : ContentPartRecord
{
public virtual ContactClientListEnum ContactClient { get; set; }
}
再次,替换发生在上面这个部分之后。
谢谢!
答案 0 :(得分:0)
如果它们位于不同的模块中,则需要引用定义枚举的引用,该枚举被添加到记录所在模块的项目中。如果已经是这种情况,您可能只是在cs文件上缺少一个using语句。