MrWhippy
MrWhippy

Reputation: 15

add property to interface

I have an interface (from another Framework that I cannot directly modify) that looks like the following:

public interface IUserDemo
{
string UserName { get; }
}

I would like to 'extend' this interface so it looks like the following:

public interface IUserDemo
{
string UserName { get; }
string Password { get; }
}

The solution will hopefully allow me to do the following:

  UserDemo demouser = new UserDemo();
  return new UserDemo
   {            
      UserName = userName,
      Password = password
   };

Where UserDemo simply looks like:

public class UserDemo : IUserDemo
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

If anyone can nudge me in the right direction that would be great!

Upvotes: 1

Views: 391

Answers (1)

Rick Su
Rick Su

Reputation: 16440

You can extend IUserDemo like the following

public interface IMyUserDemo : IUserDemo
{
    string Password { get; }
}

Implement your extended interface IMyUserDemo

public class UserDemo : IMyUserDemo
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

Upvotes: 5

Related Questions