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>
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 ());
+ }
}
}
/// created by - Nick
/// created on - 2/24/2002 10:43:57 PM
/// </remarks>
- class MissingEvent : MissingProperty {
+ class MissingEvent : MissingMember {
// e.g. <method name="Equals" status="missing"/>
public MissingEvent (MemberInfo infoMono, MemberInfo infoMS) : base (infoMono, infoMS) {}
+ MissingMethod mmAdd;
+ MissingMethod mmRemove;
MissingMethod mmRaise;
public override string Type {
return "event";
}
}
- /// <summary>
- /// a place holder for the method used to set the value of this property
- /// </summary>
- public virtual MissingMethod RaiseMethod
+
+ public override NodeStatus Analyze ()
{
- get { return mmRaise; }
- set
+ m_nodeStatus = base.Analyze ();
+
+ EventInfo eiMono = (EventInfo) mInfoMono;
+ EventInfo eiMS = (EventInfo) mInfoMS;
+
+ MemberInfo miAddMono, miRemoveMono, miRaiseMono;
+ if (eiMono == null)
+ miAddMono = miRemoveMono = miRaiseMono = null;
+ else
{
- if (mmRaise != null)
- m_nodeStatus.SubChildren (mmRaise.Status);
- mmRaise = value;
- if (mmRaise != null)
- m_nodeStatus.AddChildren (mmRaise.Status);
+ miAddMono = eiMono.GetAddMethod ();
+ miRemoveMono = eiMono.GetRemoveMethod ();
+ miRaiseMono = eiMono.GetRaiseMethod ();
+ }
+
+ MemberInfo miAddMS, miRemoveMS, miRaiseMS;
+ if (eiMS == null)
+ miAddMS = miRemoveMS = miRaiseMS = null;
+ else
+ {
+ miAddMS = eiMS.GetAddMethod ();
+ miRemoveMS = eiMS.GetRemoveMethod ();
+ miRaiseMS = eiMS.GetRaiseMethod ();
+ }
+
+ if (miAddMono != null || miAddMS != null)
+ {
+ mmAdd = new MissingMethod (miAddMono, miAddMS);
+ m_nodeStatus.AddChildren (mmAdd.Analyze ());
+ }
+ if (miRemoveMono != null || miRemoveMS != null)
+ {
+ mmRemove = new MissingMethod (miRemoveMono, miRemoveMS);
+ m_nodeStatus.AddChildren (mmRemove.Analyze ());
+ }
+ if (miRaiseMono != null || miRaiseMS != null)
+ {
+ mmRaise = new MissingMethod (miRemoveMono, miRemoveMS);
+ m_nodeStatus.AddChildren (mmRaise.Analyze ());
}
+ return m_nodeStatus;
}
public override XmlElement CreateXML (XmlDocument doc)
eltAccessors = doc.CreateElement ("accessors");
eltMember.AppendChild (eltAccessors);
}
-
+ if (mmAdd != null)
+ {
+ XmlElement eltAdd = mmAdd.CreateXML (doc);
+ eltAccessors.AppendChild (eltAdd);
+ }
+ if (mmRemove != null)
+ {
+ XmlElement eltRemove = mmRemove.CreateXML (doc);
+ eltAccessors.AppendChild (eltRemove);
+ }
if (mmRaise != null)
{
XmlElement eltRaise = mmRaise.CreateXML (doc);
FieldInfo fiMS = (FieldInfo) mInfoMS;
AddFakeAttribute (fiMono.IsNotSerialized, fiMS.IsNotSerialized, "System.NonSerializedAttribute");
+ AddFakeAttribute (fiMono.IsPinvokeImpl, fiMS.IsPinvokeImpl, "System.PInvokeImplAttribute");
+
+ AddFlagWarning (fiMono.IsStatic, fiMS.IsStatic, "static");
+ AddFlagWarning (fiMono.IsLiteral, fiMS.IsLiteral, "const");
+ AddFlagWarning (fiMono.IsInitOnly, fiMS.IsInitOnly, "readonly");
}
return m_nodeStatus;
}
(mInfoMono == null) ? null : mInfoMono.GetCustomAttributes (false),
(mInfoMS == null) ? null : mInfoMS.GetCustomAttributes (false),
rgAttributes);
+
+ if (mInfoMono != null && mInfoMS != null)
+ {
+ Accessibility acMono = GetAccessibility (mInfoMono);
+ Accessibility acMS = GetAccessibility (mInfoMS);
+ if (acMono != acMS)
+ Status.AddWarning ("Should be "+AccessibilityToString (acMS));
+ }
+
m_nodeStatus.Add (nsAttributes);
}
return m_nodeStatus;
return (mi.MemberType).ToString () + mi.ToString ();
}
+ public static Accessibility GetAccessibility (MemberInfo mi)
+ {
+ switch (mi.MemberType)
+ {
+ case MemberTypes.Constructor:
+ case MemberTypes.Method:
+ MethodBase mb = (MethodBase) mi;
+ if (mb.IsPublic)
+ return Accessibility.Public;
+ else if (mb.IsAssembly)
+ return Accessibility.Assembly;
+ else if (mb.IsFamilyOrAssembly)
+ return Accessibility.FamilyOrAssembly;
+ else if (mb.IsFamily)
+ return Accessibility.Family;
+ else if (mb.IsFamilyAndAssembly)
+ return Accessibility.FamilyAndAssembly;
+ else if (mb.IsPrivate)
+ return Accessibility.Private;
+ break;
+ case MemberTypes.Field:
+ FieldInfo fi = (FieldInfo) mi;
+ if (fi.IsPublic)
+ return Accessibility.Public;
+ else if (fi.IsAssembly)
+ return Accessibility.Assembly;
+ else if (fi.IsFamilyOrAssembly)
+ return Accessibility.FamilyOrAssembly;
+ else if (fi.IsFamily)
+ return Accessibility.Family;
+ else if (fi.IsFamilyAndAssembly)
+ return Accessibility.FamilyAndAssembly;
+ else if (fi.IsPrivate)
+ return Accessibility.Private;
+ break;
+ case MemberTypes.NestedType:
+ Type ti = (Type) mi;
+ if (ti.IsNestedPublic)
+ return Accessibility.Public;
+ if (ti.IsNestedAssembly)
+ return Accessibility.Assembly;
+ else if (ti.IsNestedFamORAssem)
+ return Accessibility.FamilyOrAssembly;
+ else if (ti.IsNestedFamily)
+ return Accessibility.Family;
+ else if (ti.IsNestedFamANDAssem)
+ return Accessibility.FamilyAndAssembly;
+ else if (ti.IsNestedPrivate)
+ return Accessibility.Private;
+ break;
+ case MemberTypes.Event:
+ case MemberTypes.Property:
+ return Accessibility.Public;
+ default:
+ throw new Exception ("Missing handler for MemberType: "+mi.MemberType.ToString ());
+ }
+ throw new Exception ("Invalid accessibility: "+mi.ToString ());
+ }
}
}
return "method";
}
}
+
+ public override NodeStatus Analyze ()
+ {
+ m_nodeStatus = base.Analyze ();
+
+ if (mInfoMono != null && mInfoMS != null)
+ {
+ MethodBase miMono = (MethodBase) mInfoMono;
+ MethodBase miMS = (MethodBase) mInfoMS;
+
+ AddFlagWarning (miMono.IsAbstract, miMS.IsAbstract, "abstract");
+ AddFlagWarning (miMono.IsStatic, miMS.IsStatic, "static");
+ AddFlagWarning (miMono.IsVirtual && !miMono.IsFinal, miMS.IsVirtual && !miMS.IsFinal, "virtual");
+ AddFlagWarning (miMono.IsConstructor, miMS.IsConstructor, "a constructor");
+ //AddFlagWarning (miMono.IsFinal, miMS.IsFinal, "sealed");
+ }
+ return m_nodeStatus;
+ }
}
}
protected MissingMethod mmGet;
protected MissingMethod mmSet;
- /// <summary>
- /// a place holder for the method used to get the value of this property
- /// </summary>
- public virtual MissingMethod GetMethod
+ public override NodeStatus Analyze ()
{
- get { return mmGet; }
- set
+ m_nodeStatus = base.Analyze ();
+
+ PropertyInfo piMono = (PropertyInfo) mInfoMono;
+ PropertyInfo piMS = (PropertyInfo) mInfoMS;
+
+ MemberInfo miGetMono, miSetMono;
+ if (piMono == null)
+ miGetMono = miSetMono = null;
+ else
{
- if (mmGet != null)
- m_nodeStatus.SubChildren (mmGet.Status);
- mmGet = value;
- if (mmGet != null)
- m_nodeStatus.AddChildren (mmGet.Status);
+ miGetMono = piMono.GetGetMethod ();
+ miSetMono = piMono.GetSetMethod ();
}
- }
- /// <summary>
- /// a place holder for the method used to set the value of this property
- /// </summary>
- public virtual MissingMethod SetMethod
- {
- get { return mmSet; }
- set
+ MemberInfo miGetMS, miSetMS;
+ if (piMS == null)
+ miGetMS = miSetMS = null;
+ else
+ {
+ miGetMS = piMS.GetGetMethod ();
+ miSetMS = piMS.GetSetMethod ();
+ }
+
+ if (miGetMono != null || miGetMS != null)
{
- if (mmSet != null)
- m_nodeStatus.SubChildren (mmSet.Status);
- mmSet = value;
- if (mmSet != null)
- m_nodeStatus.AddChildren (mmSet.Status);
+ mmGet = new MissingMethod (miGetMono, miGetMS);
+ m_nodeStatus.AddChildren (mmGet.Analyze ());
}
+ if (miSetMono != null || miSetMS != null)
+ {
+ mmSet = new MissingMethod (miSetMono, miSetMS);
+ m_nodeStatus.AddChildren (mmSet.Analyze ());
+ }
+ return m_nodeStatus;
}
+
public override XmlElement CreateXML (XmlDocument doc)
{
XmlElement eltMember = base.CreateXML (doc);
public override XmlElement CreateXML (XmlDocument doc)
{
XmlElement eltClass = base.CreateXML (doc);
- //m_nodeStatus.SetAttributes (eltClass);
-
XmlElement eltMember;
-// eltMember = MissingBase.CreateMemberCollectionElement ("attributes", rgAttributes, nsAttributes, doc);
-// if (eltMember != null)
-// eltClass.AppendChild (eltMember);
-
eltMember = MissingBase.CreateMemberCollectionElement ("methods", rgMethods, nsMethods, doc);
if (eltMember != null)
eltClass.AppendChild (eltMember);
Hashtable htMono = new Hashtable ();
if (typeMono != null)
{
+ ArrayList rgIgnoreMono = new ArrayList ();
foreach (MemberInfo miMono in typeMono.GetMembers (BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
if (typeMono == miMono.DeclaringType)
{
string strName = MissingMember.GetUniqueName (miMono);
htMono.Add (strName, miMono);
+
+ // ignore any property/event accessors
+ if (miMono.MemberType == MemberTypes.Property)
+ {
+ PropertyInfo pi = (PropertyInfo) miMono;
+ MemberInfo miGet = pi.GetGetMethod ();
+ if (miGet != null)
+ rgIgnoreMono.Add (miGet);
+ MemberInfo miSet = pi.GetSetMethod ();
+ if (miSet != null)
+ rgIgnoreMono.Add (miSet);
+ }
+ else if (miMono.MemberType == MemberTypes.Event)
+ {
+ EventInfo ei = (EventInfo) miMono;
+ MemberInfo miAdd = ei.GetAddMethod ();
+ if (miAdd != null)
+ rgIgnoreMono.Add (miAdd);
+ MemberInfo miRemove = ei.GetRemoveMethod ();
+ if (miRemove != null)
+ rgIgnoreMono.Add (miRemove);
+ MemberInfo miRaise = ei.GetRaiseMethod ();
+ if (miRaise != null)
+ rgIgnoreMono.Add (miRaise);
+ }
}
}
+ foreach (MemberInfo miIgnore in rgIgnoreMono)
+ htMono.Remove (MissingMember.GetUniqueName (miIgnore));
}
Hashtable htMethodsMS = new Hashtable ();
if (typeMS != null)
{
- foreach (MemberInfo miMS in typeMS.GetMembers (BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
+ ICollection colMembersMS = typeMS.GetMembers (BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ Hashtable htIgnoreMS = new Hashtable ();
+ foreach (MemberInfo miMS in colMembersMS)
+ {
+ // ignore any property/event accessors
+ if (miMS.MemberType == MemberTypes.Property)
+ {
+ PropertyInfo pi = (PropertyInfo) miMS;
+ MemberInfo miGet = pi.GetGetMethod ();
+ if (miGet != null)
+ htIgnoreMS.Add (miGet, miMS);
+ MemberInfo miSet = pi.GetSetMethod ();
+ if (miSet != null)
+ htIgnoreMS.Add (miSet, miMS);
+ }
+ else if (miMS.MemberType == MemberTypes.Event)
+ {
+ EventInfo ei = (EventInfo) miMS;
+ MemberInfo miAdd = ei.GetAddMethod ();
+ if (miAdd != null)
+ htIgnoreMS.Add (miAdd, miMS);
+ MemberInfo miRemove = ei.GetRemoveMethod ();
+ if (miRemove != null)
+ htIgnoreMS.Add (miRemove, miMS);
+ MemberInfo miRaise = ei.GetRaiseMethod ();
+ if (miRaise != null)
+ htIgnoreMS.Add (miRaise, miMS);
+ }
+ }
+ foreach (MemberInfo miMS in colMembersMS)
{
- if (miMS != null && miMS.DeclaringType == typeMS)
+ if (miMS != null && miMS.DeclaringType == typeMS && !htIgnoreMS.Contains (miMS))
{
string strNameUnique = MissingMember.GetUniqueName (miMS);
MemberInfo miMono = (MemberInfo) htMono [strNameUnique];
{
bool fVisibleMono = IsVisible (miMono);
+ /*
if (fVisibleMS != fVisibleMono)
{
if (fVisibleMS)
else
mm.Status.AddWarning ("Should be hidden");
}
+ */
if (miMono.MemberType != miMS.MemberType)
{
}
}
- // sort out the properties
- foreach (MissingProperty property in rgProperties)
- {
- MemberInfo infoBest = property.BestInfo;
- if (infoBest is PropertyInfo)
- {
- PropertyInfo pi = (PropertyInfo) property.BestInfo;
- MethodInfo miGet = pi.GetGetMethod (true);
- MethodInfo miSet = pi.GetSetMethod (true);
-
- if (miGet == null)
- miGet = ((PropertyInfo) property.Info).GetGetMethod (true);
-
- if (miSet == null)
- miSet = ((PropertyInfo) property.Info).GetSetMethod (true);
-
- MissingMethod mmGet = FindMethod (miGet);
- MissingMethod mmSet = FindMethod (miSet);
-
- if (mmGet != null)
- {
- nsMethods.SubChildren (mmGet.Status);
- rgMethods.Remove (mmGet);
- property.GetMethod = mmGet;
- }
- if (mmSet != null)
- {
- nsMethods.SubChildren (mmSet.Status);
- rgMethods.Remove (mmSet);
- property.SetMethod = mmSet;
- }
- }
- else
- {
- // TODO: handle the mistmatch case.
- Console.WriteLine ("FIXME: unhandled property mismatch.");
- }
- }
-
- // sort out the events
- foreach (MissingEvent evt in rgEvents)
- {
- MemberInfo infoBest = evt.BestInfo;
- if (infoBest is EventInfo)
- {
- EventInfo ei = (EventInfo) evt.BestInfo;
- MethodInfo miGet = ei.GetAddMethod ();
- MethodInfo miSet = ei.GetRemoveMethod ();
- MethodInfo miRaise = ei.GetRaiseMethod ();
-
- MissingMethod mmGet = FindMethod (miGet);
- MissingMethod mmSet = FindMethod (miSet);
- MissingMethod mmRaise = FindMethod (miRaise);
-
- if (mmGet != null)
- {
- nsMethods.SubChildren (mmGet.Status);
- rgMethods.Remove (mmGet);
- evt.GetMethod = mmGet;
- }
- if (mmSet != null)
- {
- nsMethods.SubChildren (mmSet.Status);
- rgMethods.Remove (mmSet);
- evt.SetMethod = mmSet;
- }
- if (mmRaise != null)
- {
- nsMethods.SubChildren (mmRaise.Status);
- rgMethods.Remove (mmRaise);
- evt.RaiseMethod = mmRaise;
- }
- }
- else
- {
- // TODO: handle the mistmatch case.
- Console.WriteLine ("FIXME: unhandled event mismatch.");
- }
- }
-
// compare the attributes
rgAttributes = new ArrayList ();
nsAttributes = MissingAttribute.AnalyzeAttributes (
// serializable attribute
AddFakeAttribute (typeMono.IsSerializable, typeMS.IsSerializable, "System.SerializableAttribute");
+ AddFakeAttribute (typeMono.IsAutoLayout, typeMS.IsAutoLayout, "System.AutoLayoutAttribute");
+ AddFakeAttribute (typeMono.IsExplicitLayout, typeMS.IsExplicitLayout, "System.ExplicitLayoutAttribute");
+ AddFakeAttribute (typeMono.IsLayoutSequential, typeMS.IsLayoutSequential, "System.SequentialLayoutAttribute");
+
+ Accessibility accessibilityMono = GetAccessibility (typeMono);
+ Accessibility accessibilityMS = GetAccessibility (typeMS);
+ if (accessibilityMono != accessibilityMS)
+ m_nodeStatus.AddWarning ("Should be "+AccessibilityToString (accessibilityMono));
+
+ AddFlagWarning (typeMono.IsSealed, typeMS.IsSealed, "sealed");
+ AddFlagWarning (typeMono.IsAbstract, typeMS.IsAbstract, "abstract");
}
// sum up the sub-sections
static bool IsVisible (MemberInfo mi)
{
+ // this is just embarrasing, couldn't they have virtualized this?
switch (mi.MemberType)
{
case MemberTypes.Constructor:
return !((FieldInfo) mi).IsPrivate && !((FieldInfo) mi).IsFamilyAndAssembly && !((FieldInfo) mi).IsAssembly;
case MemberTypes.NestedType:
return !((Type) mi).IsNestedPrivate;
- case MemberTypes.Event:
- case MemberTypes.Property:
- return true;
+ case MemberTypes.Property: // great, now we have to look at the methods
+ PropertyInfo pi = (PropertyInfo) mi;
+ MethodInfo miAccessor = pi.GetGetMethod ();
+ if (miAccessor == null)
+ miAccessor = pi.GetSetMethod ();
+ if (miAccessor == null)
+ return false;
+ return IsVisible (miAccessor);
+ case MemberTypes.Event: // ditto
+ EventInfo ei = (EventInfo) mi;
+ MethodInfo eiAccessor = ei.GetAddMethod ();
+ if (eiAccessor == null)
+ eiAccessor = ei.GetRemoveMethod ();
+ if (eiAccessor == null)
+ eiAccessor = ei.GetRaiseMethod ();
+ if (eiAccessor == null)
+ return false;
+ return IsVisible (eiAccessor);
default:
throw new Exception ("Missing handler for MemberType: "+mi.MemberType.ToString ());
}
}
+
+ static Accessibility GetAccessibility (Type type)
+ {
+ if (type.IsPublic)
+ return Accessibility.Public;
+ else if (type.IsNotPublic)
+ return Accessibility.Private;
+ return MissingMember.GetAccessibility (type);
+ }
}
}
ArrayList MissingTypes = new ArrayList();
ArrayList rgNamespaces = new ArrayList();
string strName;
+ Assembly assMono;
+ Assembly assMS;
Type [] rgTypesMono;
Type [] rgTypesMS;
public static ToDoAssembly Load (string strFileMono, string strName, string strNameMS)
{
Assembly assemblyMono = Assembly.LoadFrom (strFileMono);
- Type [] rgTypesMono = assemblyMono.GetTypes ();
-
Assembly assemblyMS = Assembly.LoadWithPartialName (strNameMS);
- Type [] rgTypesMS = assemblyMS.GetTypes ();
- return new ToDoAssembly (strName, rgTypesMono, rgTypesMS);
+ return new ToDoAssembly (strName, assemblyMono, assemblyMS);
}
- public ToDoAssembly (string _strName, Type [] _rgTypesMono, Type [] _rgTypesMS)
+ public ToDoAssembly (string _strName, Assembly _assMono, Assembly _assMS)
{
strName = _strName;
- rgTypesMono = _rgTypesMono;
- rgTypesMS = _rgTypesMS;
- m_nodeStatus = new NodeStatus (_rgTypesMono, _rgTypesMS);
+ assMono = _assMono;
+ assMS = _assMS;
+
+ rgTypesMono = assMono.GetTypes ();
+ rgTypesMS = assMS.GetTypes ();
+ m_nodeStatus = new NodeStatus (_assMono, _assMS);
}
public override string Name {
}
}
+ rgAttributes = new ArrayList ();
+ NodeStatus nsAttributes = MissingAttribute.AnalyzeAttributes (
+ assMono.GetCustomAttributes (true),
+ assMS.GetCustomAttributes (true),
+ rgAttributes);
+ m_nodeStatus.Add (nsAttributes);
+
return m_nodeStatus;
}
public override XmlElement CreateXML (XmlDocument doc)
{
XmlElement assemblyElem = base.CreateXML (doc);
-// m_nodeStatus.SetAttributes (assemblyElem);
if (rgNamespaces.Count > 0)
{