**** Merged from MCS ****
[mono-project.git] / mcs / tools / corcompare / MissingBase.cs
blobec62043a32a6e599c84720602c4e9eb153e3aa39
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;
12 namespace Mono.Util.CorCompare
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
23 protected NodeStatus m_nodeStatus;
24 protected ArrayList rgAttributes;
25 protected NodeStatus nsAttributes;
27 public enum Accessibility
29 Public,
30 Assembly,
31 FamilyOrAssembly,
32 Family,
33 FamilyAndAssembly,
34 Private,
37 /// <summary>
38 /// The name of the element (eg "System.Xml")
39 /// </summary>
40 public abstract string Name { get ; }
42 /// <summary>
43 /// The type of the element (eg "namespace")
44 /// </summary>
45 public abstract string Type { get; }
47 /// <summary>
48 /// Generates an XmlElement describint this element
49 /// </summary>
50 /// <param name="doc">The document in which to create the element</param>
51 /// <returns></returns>
52 public virtual XmlElement CreateXML (XmlDocument doc)
54 XmlElement eltMissing = doc.CreateElement (Type);
55 eltMissing.SetAttribute ("name", Name);
56 //Status.status.SetAttributes (eltMissing);
57 Status.SetAttributes (eltMissing);
59 XmlElement eltAttributes = MissingBase.CreateMemberCollectionElement ("attributes", rgAttributes, nsAttributes, doc);
60 if (eltAttributes != null)
61 eltMissing.AppendChild (eltAttributes);
63 return eltMissing;
66 public virtual NodeStatus Status
68 get { return m_nodeStatus; }
71 public abstract NodeStatus Analyze ();
73 /// <summary>
74 /// Creates an XmlElement grouping together a set of sub-elements
75 /// </summary>
76 /// <param name="name">the name of the element to create</param>
77 /// <param name="rgMembers">a list of sub-elements</param>
78 /// <param name="doc">the document in which to create the element</param>
79 /// <returns></returns>
80 public static XmlElement CreateMemberCollectionElement (string name, ArrayList rgMembers, NodeStatus ns, XmlDocument doc)
82 XmlElement element = null;
83 if (rgMembers != null && rgMembers.Count > 0)
85 element = doc.CreateElement(name);
86 foreach (MissingBase mm in rgMembers)
87 element.AppendChild (mm.CreateXML (doc));
89 //ns.SetAttributes (element);
91 return element;
93 protected void AddFakeAttribute (bool fMono, bool fMS, string strName)
95 if (fMono || fMS)
97 MissingAttribute ma = new MissingAttribute (
98 (fMono) ? strName : null,
99 (fMS) ? strName : null);
100 ma.Analyze ();
101 rgAttributes.Add (ma);
102 nsAttributes.AddChildren (ma.Status);
106 protected void AddFlagWarning (bool fMono, bool fMS, string strName)
108 if (!fMono && fMS)
109 m_nodeStatus.AddWarning ("Should be " + strName);
110 else if (fMono && !fMS)
111 m_nodeStatus.AddWarning ("Should not be " + strName);
114 protected string AccessibilityToString (Accessibility ac)
116 switch (ac)
118 case Accessibility.Public:
119 return "public";
120 case Accessibility.Assembly:
121 return "internal";
122 case Accessibility.FamilyOrAssembly:
123 return "protected internal";
124 case Accessibility.Family:
125 return "protected";
126 case Accessibility.FamilyAndAssembly:
127 return "protected"; // TODO:
128 case Accessibility.Private:
129 return "private";
131 throw new Exception ("Invalid accessibility: "+ac.ToString ());