base class for tree elements
[mono.git] / mcs / tools / corcompare / MissingBase.cs
1 // Mono.Util.CorCompare.MissingBase
2 //
3 // Author(s):
4 //   Piers Haken (piersh@friskit.com)
5 //
6 // (C) 2001-2002 Piers Haken
7 using System;
8 using System.Xml;
9 using System.Reflection;
10 using System.Collections;
11
12 namespace Mono.Util.CorCompare
13 {
14         /// <summary>
15         /// Base class for all comparison items
16         /// </summary>
17         /// <remarks>
18         ///     created by - Piersh
19         ///     created on - 3/3/2002 10:23:24 AM
20         /// </remarks>
21         public abstract class MissingBase
22         {
23                 /// <summary>
24                 /// The name of the element (eg "System.Xml")
25                 /// </summary>
26                 public abstract string Name { get ; }
27
28                 /// <summary>
29                 /// The type of the element (eg "namespace")
30                 /// </summary>
31                 public abstract string Type { get; }
32
33                 /// <summary>
34                 /// Generates an XmlElement describint this element
35                 /// </summary>
36                 /// <param name="doc">The document in which to create the element</param>
37                 /// <returns></returns>
38                 public virtual XmlElement CreateXML (XmlDocument doc)
39                 {
40                         XmlElement eltMissing = doc.CreateElement (Type);
41                         eltMissing.SetAttribute ("name", Name);
42                         eltMissing.SetAttribute ("status", Status);
43                         return eltMissing;
44                 }
45                 /// <summary>
46                 /// The CompletionType of this element (eg Missing)
47                 /// </summary>
48                 public virtual CompletionTypes Completion
49                 {
50                         get { return CompletionTypes.Missing; }
51                 }
52
53                 /// <summary>
54                 /// A textual representation of this element's completion
55                 /// </summary>
56                 public virtual string Status
57                 {
58                         get 
59                         {
60                                 switch (Completion)
61                                 {
62                                         case CompletionTypes.Missing:
63                                                 return "missing";
64                                         case CompletionTypes.Todo:
65                                                 return "todo";
66                                         case CompletionTypes.Complete:
67                                                 return "complete";
68                                         default:
69                                                 throw new Exception ("Invalid CompletionType: "+Completion.ToString ());
70                                 }
71                         }
72                 }
73
74                 /// <summary>
75                 /// Creates an XmlElement grouping together a set of sub-elements
76                 /// </summary>
77                 /// <param name="name">the name of the element to create</param>
78                 /// <param name="rgMembers">a list of sub-elements</param>
79                 /// <param name="ci">the completion info (unused)</param>
80                 /// <param name="doc">the document in which to create the element</param>
81                 /// <returns></returns>
82                 public static XmlElement CreateMemberCollectionElement (string name, ArrayList rgMembers, CompletionInfo ci, XmlDocument doc) 
83                 {
84                         XmlElement element = null;
85                         if (rgMembers != null && rgMembers.Count > 0)
86                         {
87                                 element = doc.CreateElement(name);
88                                 CompletionInfo ciMember = new CompletionInfo ();
89                                 foreach (MissingBase mm in rgMembers)
90                                 {
91                                         element.AppendChild (mm.CreateXML (doc));
92                                         ciMember.Add (mm.Completion);
93                                 }
94                                 ciMember.SetAttributes (element);
95                         }
96                         return element;
97                 }
98         }
99 }