Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extend interface c#?

I have an interface in c# , something like this:

public interface IMyInterfaceA 
{
        string Name { get; }
        int Id { get; set; }
}

I want to extend this interface to include additional property.

for example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public interface IMyInterfaceB: IMyInterfaceA
{
        string newProp { get; }
       
}

The problem is that such syntax is not valid. It required me to implement IMyInterfaceA,
so my interface will look like:

public interface IMyInterfaceB: IMyInterfaceA
{
        string newProp { get; }
         public string Vendor => throw new NotImplementedException();

        public int VendorId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}

All my goal to use inhertence is so that I wouldn’t need to have those properties again.

The IMyInterfaceAis a core inteface I cannot change.

How can I implement an extension but without rewrite the base properties?

>Solution :

There is no problem in your code example. Interfaces support inheritance from another interfaces without implementation of it’s members. Maybe your example is not the same as the code where problem occur.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading