Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MissingBase.cs « corcompare « tools « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec62043a32a6e599c84720602c4e9eb153e3aa39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Mono.Util.CorCompare.MissingBase
//
// Author(s):
//   Piers Haken (piersh@friskit.com)
//
// (C) 2001-2002 Piers Haken
using System;
using System.Xml;
using System.Reflection;
using System.Collections;

namespace Mono.Util.CorCompare
{
	/// <summary>
	/// Base class for all comparison items
	/// </summary>
	/// <remarks>
	/// 	created by - Piersh
	/// 	created on - 3/3/2002 10:23:24 AM
	/// </remarks>
	public abstract class MissingBase
	{
		protected NodeStatus m_nodeStatus;
		protected ArrayList rgAttributes;
		protected NodeStatus nsAttributes;

		public enum Accessibility
		{
			Public,
			Assembly,
			FamilyOrAssembly,
			Family,
			FamilyAndAssembly,
			Private,
		}

		/// <summary>
		/// The name of the element (eg "System.Xml")
		/// </summary>
		public abstract string Name { get ; }

		/// <summary>
		/// The type of the element (eg "namespace")
		/// </summary>
		public abstract string Type { get; }

		/// <summary>
		/// Generates an XmlElement describint this element
		/// </summary>
		/// <param name="doc">The document in which to create the element</param>
		/// <returns></returns>
		public virtual XmlElement CreateXML (XmlDocument doc)
		{
			XmlElement eltMissing = doc.CreateElement (Type);
			eltMissing.SetAttribute ("name", Name);
			//Status.status.SetAttributes (eltMissing);
			Status.SetAttributes (eltMissing);

			XmlElement eltAttributes = MissingBase.CreateMemberCollectionElement ("attributes", rgAttributes, nsAttributes, doc);
			if (eltAttributes != null)
				eltMissing.AppendChild (eltAttributes);

			return eltMissing;
		}

		public virtual NodeStatus Status
		{
			get { return m_nodeStatus; }
		}

		public abstract NodeStatus Analyze ();

		/// <summary>
		/// Creates an XmlElement grouping together a set of sub-elements
		/// </summary>
		/// <param name="name">the name of the element to create</param>
		/// <param name="rgMembers">a list of sub-elements</param>
		/// <param name="doc">the document in which to create the element</param>
		/// <returns></returns>
		public static XmlElement CreateMemberCollectionElement (string name, ArrayList rgMembers, NodeStatus ns, XmlDocument doc)
		{
			XmlElement element = null;
			if (rgMembers != null && rgMembers.Count > 0)
			{
				element = doc.CreateElement(name);
				foreach (MissingBase mm in rgMembers)
					element.AppendChild (mm.CreateXML (doc));

				//ns.SetAttributes (element);
			}
			return element;
		}
		protected void AddFakeAttribute (bool fMono, bool fMS, string strName)
		{
			if (fMono || fMS)
			{
				MissingAttribute ma = new MissingAttribute (
					(fMono) ? strName : null,
					(fMS) ? strName : null);
				ma.Analyze ();
				rgAttributes.Add (ma);
				nsAttributes.AddChildren (ma.Status);
			}
		}

		protected void AddFlagWarning (bool fMono, bool fMS, string strName)
		{
			if (!fMono && fMS)
				m_nodeStatus.AddWarning ("Should be " + strName);
			else if (fMono && !fMS)
				m_nodeStatus.AddWarning ("Should not be " + strName);
		}

		protected string AccessibilityToString (Accessibility ac)
		{
			switch (ac)
			{
				case Accessibility.Public:
					return "public";
				case Accessibility.Assembly:
					return "internal";
				case Accessibility.FamilyOrAssembly:
					return "protected internal";
				case Accessibility.Family:
					return "protected";
				case Accessibility.FamilyAndAssembly:
					return "protected";	// TODO:
				case Accessibility.Private:
					return "private";
			}
			throw new Exception ("Invalid accessibility: "+ac.ToString ());
		}
	}
}