不知道这里出了什么问题,但我正试图在我创建的接口中使用enum。
当我尝试实现接口时,我得到错误
可访问性不一致:属性类型为"System.Collections.Generic"。
列表 属性
Enum
namespace BusinessEntities
{
public class AddressTypeValues
{
[DataContract(Name = "AddressType")]
public enum AddressType
{
[EnumMember(Value = "Home")]
Home,
[EnumMember(Value = "Mailing")]
Mailing,
[EnumMember(Value = "Location")]
Location,
[EnumMember(Value = "Other")]
Other
}
}
}
界面
namespace BusinessEntities
{
public interface IAgentAddress
{
AddressTypeValues.AddressType AddressType { get; set; }
String? Street1 { get; set; }
String? Street2 { get; set; }
String? Street3 { get; set; }
String? City { get; set; }
String? State { get; set; }
String? ZipCode { get; set; }
}
}
使用addresstype的类
namespace BusinessEntities
{
[DataContract]
public class CloneMessage : ICloneMessage
{
[DataMember]
public AgentTransmission AgentInformation { get; set; }
[DataMember]
public IList<AgentAddress> AgentAddresses { get; set; }
[DataMember]
public IList<RelationshipCode> RelationshipCodes { get; set; }
[DataMember]
public string? ErrorMessages { get; set; }
public CloneMessage(){}
}
}
namespace BusinessEntities
{
[DataContract]
public class AgentAddress : IAgentAddress
{
[DataMember]
public AddressTypeValues.AddressType AddressType { get; set; }
[DataMember]
public string Street1 { get; set; }
[DataMember]
public string Street2 { get; set; }
[DataMember]
public string Street3 { get; set; }
[DataMember]
public string City { get; set; }
[DataMember]
public string State { get; set; }
[DataMember]
public string ZipCode { get; set; }
}
}
您的代码中有几个错误。
。你的班级AgentAddress
没有标记为public
。这就是你得到错误的原因。可能您的类没有定义任何访问说明符,它被认为是internal
。将类设置为public
将消除错误。
代码中的第二个问题是您正在使用String?
。可能试图使字符串为Nullable<T>
。String已经是一个引用类型,它可以保存null。你需要用String?
删除?
。所以你的界面看起来像:
public interface IAgentAddress
{
AddressTypeValues.AddressType AddressType { get; set; }
String Street1 { get; set; }
String Street2 { get; set; }
String Street3 { get; set; }
String City { get; set; }
String State { get; set; }
String ZipCode { get; set; }
}
Nullable<T>
或带有?
的类型用于值类型,因为值类型不能像int?
或Nullable<int>
那样包含null