我面临有关接口扩展接口的问题。让我们举个例子
public interface IBaseClient
{
int PatientId { get; set; }
string PatientName { get; set; }
}
public interface IEchoClient2 : IBaseClient
{
string StudyInstanceUID{ get; set; }
}
我正在将这个接口IEchoClient2实现到类中。
class RestClient2 : IEchoClient2
{
public string StudyInstanceUID
{
get;
set;
}
new public int PatientId
{
get;
set;
}
new public string PatientName
{
get;
set;
}
static void Main(string[] args)
{
IEchoClient2 client2 = new RestClient2();
client2.PatientId = 1;
client2.PatientName = "XYZ";
client2.StudyInstanceUID = "11";
JsonSerializer objJsonSerializer = new JsonSerializer();
objJsonSerializer.JsonConverter(client2);
}
}
public class JsonSerializer
{
public void JsonConverter(IEchoClient2 client2)
{
JsonRestService.JsonRESTClient client = new JsonRestService.JsonRESTClient();
}
}
但是当我将接口对象传递给JsonConverter(IEchoClient2 client2)
方法时,它只显示IClient2接口属性。我如何获得所有基本接口支柱以及派生接口支柱。
在此图像中,您将观察到只有StudyInstanceUID显示的不是其他两个道具。
我怎样才能获得这两个基本接口的支持。
答案 0 :(得分:1)
您关心的只是调试器的工作原理。属性存在,但调试器默认情况下将视图限制为直接类的声明属性。你需要扩展" client2"在调试器的变量值工具提示窗口中查看其他基本属性。
请注意,如果您在实际使用client
的方法中编写了任何代码,则所有属性都可以直接使用(例如通过Intellisense)。它只是调试器试图不用太多的信息轰炸你,导致在调试时不能立即看到属性。