2017-10-11 67 views
0
public interface IMyService 
{ 
    void GetValue(); 
} 

public class MyService : ClientBase<IMyService>, IMyService 
{ 
    public MyService() 
    { 
     EndPoint = "Test"; 
    } 
    public void GetValue() 
    { 

    } 
} 
public interface ICommunication 
{ 
    void Start(); 
} 

public class ClientBase<T> : ICommunication 
{ 
    public string EndPoint { get; set; } 
    public void Start() 
    { 
    } 
} 

我的测试项目中读取基类的属性如何从我的接口实例

[TestClass] 
public class UnitTest1 
{ 
    [TestMethod] 
    public void TestMethod1() 
    { 
     ICommunication communication = new MyService(); 
    } 
} 

如何访问从通信对象的EndPoint属性?

我的目标是从ICommunication实例中读取EndPoint的值。如何转换的ICommunication接口ClientBase泛型类

注:我们有多个服务classes.Is有没有办法从我ICommunication

回答

0

接口ICommunication得到ClientBase的实例没有EndPoint,当你写这行代码:

ICommunication communication = new MyService(); 

communicationICommunication类型的参考,但它指向的MyService一个实例。因此,你可以这样做,把它投到MyService,然后访问它:

string ep = (communication as MyService).EndPoint; 
+0

我忘了把这一个。我们有多个服务类。有没有办法从我的ICommunication中获得ClientBase 的实例 –