Reputation: 10699
Not sure what's wrong here but I am trying to use an enum in an interface I've created.
When I attempt to implement the interface I get the error
Inconsistent accessibility: property type 'System.Collections.Generic.IList' is less accessible than property 'BusinessEntities.ICloneMessage.AgentAddresses'
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
}
}
}
Interface
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; }
}
}
Classes using 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; }
}
}
Upvotes: 0
Views: 13048
Reputation: 223277
There are couple of errors in your code.
First. Your class AgentAddress
is not marked as public
. That is why you are getting the error. Probably your class is not defined with any access specifier and it is considered as internal
. Making your class public
would remove the error.
Second problem in your code is that you are using String?
. May be trying to make string as Nullable<T>
. String is already a reference type, it can hold null. You need to remove ?
with String?
. So your interface would look like:
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>
or type with ?
is used for value types, since value types can't hold null
like int?
or Nullable<int>
Upvotes: 4