added support for struct, interfaces, delegates & enums
[mono.git] / mcs / tools / corcompare / MissingType.cs
1 // Mono.Util.CorCompare.MissingType
2 //
3 // Author(s):
4 //   Nick Drochak (ndrochak@gol.com)
5 //
6 // (C) 2001-2002 Nick Drochak
7
8 using System;
9 using System.Xml;
10
11 namespace Mono.Util.CorCompare {
12
13         /// <summary>
14         ///     Represents a class method that missing.
15         /// </summary>
16         /// <remarks>
17         ///     created by - Nick
18         ///     created on - 2/20/2002 10:43:57 PM
19         /// </remarks>
20         class MissingType
21         {
22                 // e.g. <class name="System.Byte" status="missing"/>
23                 protected Type theType;
24                 public MissingType(Type t) 
25                 {
26                         theType = t;
27                 }
28
29                 public override bool Equals(object o) 
30                 {
31                         if (o is MissingType) 
32                         {
33                                 return o.GetHashCode() == this.GetHashCode();
34                         }
35                         return false;
36                 }
37
38                 public override int GetHashCode() 
39                 {
40                         return theType.GetHashCode();
41                 }
42
43                 public string Name 
44                 {
45                         get 
46                         {
47                                 return theType.Name;
48                         }
49                 }
50
51                 public string NameSpace 
52                 {
53                         get 
54                         {
55                                 return theType.Namespace;
56                         }
57                 }
58
59                 public virtual string Status 
60                 {
61                         get 
62                         {
63                                 return "missing";
64                         }
65                 }
66                 public bool IsDelegate
67                 {
68                         get
69                         {
70                                 if (theType.IsEnum || theType.IsInterface || theType.IsValueType)
71                                         return false;
72                                 Type type = theType.BaseType;
73                                 while (type != null)
74                                 {
75                                         if (type.FullName == "System.Delegate")
76                                                 return true;
77                                         type = type.BaseType;
78                                 }
79                                 return false;
80                         }
81                 }
82                 public virtual XmlElement CreateXML (XmlDocument doc)
83                 {
84                         XmlElement eltClass;
85                         if (theType.IsEnum)
86                                 eltClass = doc.CreateElement ("enum");
87                         else if (theType.IsInterface)
88                                 eltClass = doc.CreateElement ("interface");
89                         else if (IsDelegate)
90                                 eltClass = doc.CreateElement ("delegate");
91                         else if (theType.IsValueType)
92                                 eltClass = doc.CreateElement ("struct");
93                         else
94                                 eltClass = doc.CreateElement ("class");
95
96                         eltClass.SetAttribute ("name", Name);
97                         eltClass.SetAttribute ("status", Status);
98
99                         return eltClass;
100                 }
101         }
102 }