简体   繁体   中英

C# create a hierachical object

I am creating a logging system. It is very basic and a good exercise to learn about creating classes. However, I'm stuck and have been on this for a week.

The project is a copy and paste project (a backup solution) and for each file it copies, I want to save the following: The Title, Status and MoreDetails (all of type string).

I would like to see the title of the file and the status at root level, but I would like to drill deeper in to see the moreDetails. I hope the 'textual diagram' below will help illustrate my point.

-logFile
-0
      Title         Value
      Status        Value
     +MoreDetails
-1
      Title         Value
      Status        Value
     +MoreDetails
-2
      Title         Value
      Status        Value
     +MoreDetails

Please note, I don't want to write this to a file/database as I want to have this in memory - I know this may not be a good idea but it's an exercise at present.

As per the comment of OP, it is answered by TI, to use the Composite Pattern

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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