简体   繁体   English

在接口成员C#中使用接口名称

[英]Using interface name in interface members C#

I have four classes as: 我有四个班级:

Author.cs class ie Author.cs类,即

public class Author : Interfaces.INode
{
        public int _aID { get; set; }
        public string _aName { get; set; }
        public List<CoAuthor> _aCoAuthors { get; set; }
        public List<Venue> _aVenue { get; set; }
        public List<Paper> _aPapers { get; set; }

        public string _aArea { get; set; }
}  

CoAuthor.cs class ie CoAuthor.cs类,即

public class CoAuthor : Interfaces.INode
{
        public int _coaID { get; set; }
        public string _coaName { get; set; }
        public List<Paper> _coaPapers { get; set; }

        public string _coaArea { get; set; }
}  

Venue.cs class ie Venue.cs类,即

public class Venue : Interfaces.INode
{
    public int _vID { get; set; }
    public string _vName { get; set; }
    public List<Paper> _vPapers { get; set; }

    public string _vArea { get; set; }
}  

Paper.cs class ie Paper.cs类,即

public class Paper : Interfaces.INode
{
    public int _pID { get; set; }
    public Author _pAuthor { get; set; }
    public List<CoAuthor> _pCoAuthors { get; set; }
    public Venue _pVenue { get; set; }
    public int _pYear { get; set; }
    public string _pRField { get; set; }
}  

All of these classes are implementing an interface ie Interfaces.INode which is defined as: 所有这些类都实现一个interfaceInterfaces.INode ,其定义为:

public interface INode
{
        List<INode> _TargetObject { get; }
        List<INode> _AttributeObject { get; }
}  

Now Author.cs class is of type _TargetObject ie defined in INode and all of the other 3 classes are of type _AttributeObject ie defined in INode . 现在Author.cs类的类型为_TargetObject即在INode定义,所有其他3个类的类型为_AttributeObject即在INode定义。

How can I link these classes with corresponding INode members as currently its not clear that which are _TargetObject and _AttributeObject ? 我如何将这些类与相应的INode成员链接,因为目前尚不清楚_TargetObject_AttributeObject_AttributeObject

As explained in comment, i suggest you to define better objects and tiping. 如评论中所述,我建议您定义更好的对象和技巧。 In this implementation you have more control of what types are Target and what are attributes 在此实现中,您可以更好地控制目标是什么类型和属性是什么

public interface INode
{
        List<INode> _TargetObject { get; }
        List<IAttribute> _AttributeObject { get; }
}  

public interface IAttribute : INode
{

}  

public class Author : Interfaces.INode
{
     private List<INode> _targetList ;
     private List<IAttribute> _attributeObject ;
     public Author()
     {
         _targetList = new List<INode>();
     }
     //implementazion of _TargetObject INode method
     public List<INode> _TargetObject 
     { 
         get  
         {
             return _targetList;
         }
     }
     //implementazion of _AttributeObject INode method
     public List<IAttribute> _AttributeObject 
     { 
         get  
         {
             return _attributeObject ;
         }
     }

} 

public class CoAuthor : Interfaces.IAttribute 
{... your class implementation ...}
public class Venue : Interfaces.IAttribute
{... your class implementation ...}
public class Paper : Interfaces.IAttribute
{... your class implementation ...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM