1 // Mono.Util.CorCompare.ToDoAssembly
4 // Nick Drochak (ndrochak@gol.com)
6 // (C) 2001-2002 Nick Drochak
9 using System.Reflection;
10 using System.Collections;
15 namespace Mono.Util.CorCompare {
18 /// Represents an assembly that has missing or MonoTODO classes
22 /// created on - 2/20/2002 10:43:57 PM
24 class ToDoAssembly : MissingBase
26 // these types are in mono corlib, but not in the dll we are going to examine.
27 ArrayList MissingTypes = new ArrayList();
28 ArrayList rgNamespaces = new ArrayList();
35 protected static Hashtable htGhostTypes;
36 private static string[] rgstrGhostTypes = {"System.Object", "System.ValueType", "System.Delegate", "System.Enum"};
39 static ToDoAssembly ()
41 htGhostTypes = new Hashtable ();
43 foreach (string strGhostType in rgstrGhostTypes)
45 htGhostTypes.Add (strGhostType, null);
49 public static ToDoAssembly Load (string strFileMono, string strName, string strNameMS)
51 Assembly assemblyMono = Assembly.LoadFrom (strFileMono);
52 Assembly assemblyMS = Assembly.LoadWithPartialName (strNameMS);
54 return new ToDoAssembly (strName, assemblyMono, assemblyMS);
57 public ToDoAssembly (string _strName, Assembly _assMono, Assembly _assMS)
63 rgTypesMono = assMono.GetTypes ();
64 rgTypesMS = assMS.GetTypes ();
65 m_nodeStatus = new NodeStatus (_assMono, _assMS);
68 public override string Name {
74 public override string Type
76 get { return "assembly"; }
79 private Hashtable GetNamespaceMap (Type [] rgTypes)
81 Hashtable mapTypes = new Hashtable ();
82 foreach (Type t in rgTypes)
86 string strName = t.FullName;
87 string strNamespace = t.Namespace;
88 if (strNamespace != null && strNamespace.Length > 0 &&
89 strName != null && strName.Length > 0 &&
90 !htGhostTypes.Contains (strName))
92 ArrayList rgContainedTypes = (ArrayList) mapTypes [strNamespace];
93 if (rgContainedTypes == null)
95 rgContainedTypes = new ArrayList ();
96 mapTypes [strNamespace] = rgContainedTypes;
98 rgContainedTypes.Add (t);
105 public override NodeStatus Analyze ()
107 Hashtable mapTypesMono = GetNamespaceMap (rgTypesMono);
108 Hashtable mapTypesMS = GetNamespaceMap (rgTypesMS);
110 foreach (string strNamespaceMS in mapTypesMS.Keys)
112 if (strNamespaceMS != null)
114 ArrayList rgContainedTypesMS = (ArrayList) mapTypesMS [strNamespaceMS];
115 ArrayList rgContainedTypesMono = (ArrayList) mapTypesMono [strNamespaceMS];
116 MissingNameSpace mns = new MissingNameSpace (strNamespaceMS, rgContainedTypesMono, rgContainedTypesMS);
117 NodeStatus nsNamespace = mns.Analyze ();
118 m_nodeStatus.AddChildren (nsNamespace);
119 if (rgTypesMono != null)
120 mapTypesMono.Remove (strNamespaceMS);
121 rgNamespaces.Add (mns);
124 foreach (string strNamespaceMono in mapTypesMono.Keys)
126 if (strNamespaceMono != null)
128 ArrayList rgContainedTypesMono = (ArrayList) mapTypesMono [strNamespaceMono];
129 MissingNameSpace mns = new MissingNameSpace (strNamespaceMono, rgContainedTypesMono, null);
130 NodeStatus nsNamespace = mns.Analyze ();
131 m_nodeStatus.AddChildren (nsNamespace);
132 rgNamespaces.Add (mns);
136 rgAttributes = new ArrayList ();
137 NodeStatus nsAttributes = MissingAttribute.AnalyzeAttributes (
138 assMono.GetCustomAttributes (true),
139 assMS.GetCustomAttributes (true),
141 m_nodeStatus.Add (nsAttributes);
147 public string CreateClassListReport() {
149 if (rgNamespaces.Count == 0) return "";
151 StringBuilder output = new StringBuilder();
152 foreach (MissingNameSpace ns in rgNamespaces)
154 string[] missingTypes = ns.MissingTypeNames(true);
155 if (missingTypes != null && missingTypes.Length > 0) {
156 string joinedNames = String.Join("\n", missingTypes);
157 output.Append(joinedNames + "\n");
160 return output.ToString();
163 public override XmlElement CreateXML (XmlDocument doc)
165 XmlElement assemblyElem = base.CreateXML (doc);
167 if (rgNamespaces.Count > 0)
169 XmlElement eltNamespaces = doc.CreateElement ("namespaces");
170 assemblyElem.AppendChild (eltNamespaces);
172 foreach (MissingNameSpace ns in rgNamespaces)
174 XmlElement eltNameSpace = ns.CreateXML (doc);
175 if (eltNameSpace != null)
176 eltNamespaces.AppendChild (eltNameSpace);
182 public void CreateXMLReport(string filename) {
186 outDoc = new XmlDocument();
187 outDoc.AppendChild(outDoc.CreateXmlDeclaration("1.0", null, null));
189 XmlElement assembliesElem = outDoc.CreateElement("assemblies");
190 outDoc.AppendChild(assembliesElem);
192 XmlElement assemblyElem = CreateXML (outDoc);
193 assembliesElem.AppendChild(assemblyElem);
195 outDoc.Save(filename);