-
Notifications
You must be signed in to change notification settings - Fork 0
Multiple Interfaces
Cy Scott edited this page Aug 23, 2021
·
3 revisions
Combining multiple interfaces is possible. However, when a member conflict is detected then the conflicting member will be implemented explicitly. A member conflict is detected when the member names are the same, the signature is the same (i.e. method parameter types), and the return type is not the same. The member for the first inherited interface will be the member that will be implemented implicitly and the other conflicting members will be implemented explicitly. Here is a simple example of how it works:
public interface IHaveAGetIntId
{
int Id { get; }
}
public interface IHaveAGetId
{
Guid Id { get; }
}
public interface IHaveASetId
{
Guid Id { set; }
}
[Generate]
public interface IHaveMultipleInterfaces : IHaveAGetId, IHaveASetId, IHaveAGetIntId
{
}
The generated code will look like:
public class HaveMultipleInterfacesModel : IHaveMultipleInterfaces
{
public System.Guid Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
private System.Guid _Id;
int IHaveAGetIntId.Id { get; }
public HaveMultipleInterfacesModel()
{
}
}
In this example, the get and set properties were combined for the non-conflicting property. The conflicting property was implemented explicitly.