不确定这里有什么问题,但我试图在我创建的界面中使用枚举。
当我尝试实现界面时,我收到错误
可访问性不一致:属性类型'System.Collections.Generic.IList'的可访问性低于属性'BusinessEntities.ICloneMessage.AgentAddresses'
枚举
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; }
}
}
使用AddresType的类
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; }
}
}
答案 0 :(得分:4)
您的代码中有几处错误。
首先。您的班级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>
或带有?
的类型用于值类型,因为值类型无法保持null
或int?
Nullable<int>