2017-02-16 82 views
0

我想构建一个嵌套类层次结构。一些有助于分类,比方说对象(主要是属性)按类型使用智能感知。嵌套类(或如何“组”属性)

即从

Class MyHouse 
    [+] Property Tv 
    [+] Property Kitchen 
    [+] Property Radio 
    [+] Property Bathroom 
    [+] Property Computer 
    [+] Property Crib 
    [-] Property Bedroom 
      Get... 
      Set... 
     End Property 
End class 

Class MyHouse 
    | 
    |-----Class Rooms 
    |   [+] Property Bathroom 
    |   [+] Property Bedroom 
    |   [+] Property Kitchen 
    |   ... 
    | 
    |-----Class Objects 
    |   [+] Property Radio 
    |   [+] Property Tv 
    |   [+] Property Computer 
    |   [+] Property Crib 
    |   ... 
    | 
    End class  


主要目的是有intellis使用层次结构

Dim MyHouse_ as new MyHouse() 
     ------------- 
MyHouse_.| Rooms  | 
     | Objects | 
     ------------- 


所以我嵌套类中的另一个,并共享它的成员:

Friend class MyHouse 
| 
| Friend class Rooms 
| | 
| | Private shared kitchen_ as clsRoom 
| | Friend shared Property prop_kitchen 
| |  Get 
| |  Set 
| | End Property 
| | ... 
| | 
| End class 
|  ... 
| 
End Class 

问题是,当我创建一个新的对象,并希望访问它的嵌套属性,我得到以下错误:

access of shared member constant member qualifying expression will not be evaluated  

但我不想实例化子类。

我只是在寻找一种让层级“整理”整个班级,并直接访问其成员的好方法。

任何方式做到这一点?

回答

0

回答我的问题:

正确的方法做的是简单地 - 保留两个班分开 - 在主父类中添加子类的新实例

它看起来像一个字段或一个属性(取决于所做的声明),但它会有这个“嵌套”层次结构,这是我的目标。

这让我可以组织很多更好的班级 希望这可以帮助别人