I am looking to ‘extending’ an interface by providing set accessors to properties in that interface. The interface looks something like this:
interface IUser { string UserName { get; } }
I want something like this:
interface IMutableUser : IUser { string UserName { get; set; } }
I need the inheritence. I cannot copy the body of IUser into IMutableUser and add the set accessors.
Is this possible in C#? If so, how can it be accomplished?
I don’t see any reason why what you have posted shouldn’t work? Just did a quick test and it compiles alright, but gives a warning about hiding. This can be fixed by adding the new keyword, like this:
An alternative would be to add explicit set methods; eg:
Of course, I’d prefer to use setters, but if it’s not possible, I guess you do what you have to.