Ejemplo n.º 1
0
 protected void AddFakeAttribute(bool fMono, bool fMS, string strName)
 {
     if (fMono || fMS)
     {
         var ma = new MissingAttribute(
             (fMono) ? strName : null,
             (fMS) ? strName : null);
         ma.Analyze();
         rgAttributes.Add(ma);
         nsAttributes.AddChildren(ma.Status);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// analyzes two sets of reflected attributes, generates a list
        /// of MissingAttributes according to the completion of the first set wrt the second.
        /// </summary>
        /// <param name="rgAttributesMono">mono attributes</param>
        /// <param name="rgAttributesMS">microsoft attributes</param>
        /// <param name="rgAttributes">where the results are put</param>
        /// <returns>completion info for the whole set</returns>
        public static NodeStatus AnalyzeAttributes(Object [] rgAttributesMono, Object [] rgAttributesMS, ArrayList rgAttributes)
        {
            var nodeStatus = new NodeStatus();

            var mapAttributesMono = (rgAttributesMono == null) ? new Hashtable() : GetAttributeMap(rgAttributesMono);
            var mapAttributesMS   = (rgAttributesMS == null) ? new Hashtable() : GetAttributeMap(rgAttributesMS);

            foreach (var attribute in mapAttributesMS.Values)
            {
                string strAttribute  = attribute.ToString();
                var    attributeMono = mapAttributesMono [strAttribute];
                var    ma            = new MissingAttribute(attributeMono, attribute);
                rgAttributes.Add(ma);
                var nsAttribute = ma.Analyze();
                nodeStatus.AddChildren(nsAttribute);

                if (attributeMono != null)
                {
                    mapAttributesMono.Remove(strAttribute);
                }
            }
            foreach (var attribute in mapAttributesMono.Values)
            {
                if (attribute.ToString().EndsWith("MonoTODOAttribute"))
                {
                    nodeStatus.SetError(ErrorTypes.Todo);
                    //nodeStatus.statusCountsChildren.errorCounts.Add (ErrorTypes.Todo);
                    //nodeStatus.statusCountsTotal.errorCounts.Add (ErrorTypes.Todo);
                    //nodeStatus.cTodo ++;	// this is where ALL the 'todo's come from
                }
                else if (attribute.ToString().EndsWith("DllImportAttribute") || attribute.ToString().EndsWith("PreserveSigAttribute"))
                {
                    // Ignore these
                }
                else
                {
                    var ma = new MissingAttribute(attribute, null);
                    rgAttributes.Add(ma);
                    var nsAttribute = ma.Analyze();
                    nodeStatus.AddChildren(nsAttribute);
                }
            }
            return(nodeStatus);
        }
Ejemplo n.º 3
0
        public override NodeStatus Analyze()
        {
            var mapTypesMono = GetNamespaceMap(rgTypesMono);
            var mapTypesMS   = GetNamespaceMap(rgTypesMS);

            foreach (string strNamespaceMS in mapTypesMS.Keys)
            {
                if (strNamespaceMS != null)
                {
                    var rgContainedTypesMS   = (ArrayList)mapTypesMS [strNamespaceMS];
                    var rgContainedTypesMono = (ArrayList)mapTypesMono [strNamespaceMS];
                    var mns         = new MissingNameSpace(strNamespaceMS, rgContainedTypesMono, rgContainedTypesMS);
                    var nsNamespace = mns.Analyze();
                    m_nodeStatus.AddChildren(nsNamespace);
                    if (rgTypesMono != null)
                    {
                        mapTypesMono.Remove(strNamespaceMS);
                    }
                    rgNamespaces.Add(mns);
                }
            }
            foreach (string strNamespaceMono in mapTypesMono.Keys)
            {
                if (strNamespaceMono != null)
                {
                    var rgContainedTypesMono = (ArrayList)mapTypesMono [strNamespaceMono];
                    var mns         = new MissingNameSpace(strNamespaceMono, rgContainedTypesMono, null);
                    var nsNamespace = mns.Analyze();
                    m_nodeStatus.AddChildren(nsNamespace);
                    rgNamespaces.Add(mns);
                }
            }

            rgAttributes = new ArrayList();
            var nsAttributes = MissingAttribute.AnalyzeAttributes(
                assMono.GetCustomAttributes(true),
                assMS.GetCustomAttributes(true),
                rgAttributes);

            m_nodeStatus.Add(nsAttributes);

            return(m_nodeStatus);
        }
Ejemplo n.º 4
0
        public override NodeStatus Analyze()
        {
            if (!Status.IsMissing)
            {
                rgAttributes = new ArrayList();
                nsAttributes = MissingAttribute.AnalyzeAttributes(
                    (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);
        }
Ejemplo n.º 5
0
        public override NodeStatus Analyze()
        {
            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)
            {
                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 && !htIgnoreMS.Contains(miMS))
                    {
                        string     strNameUnique = MissingMember.GetUniqueName(miMS);
                        MemberInfo miMono        = (MemberInfo)htMono [strNameUnique];

                        MissingMember mm = CreateMember(miMono, miMS);

                        bool fVisibleMS = IsVisible(miMS);
                        if (miMono == null)
                        {
                            if (fVisibleMS)
                            {
                                AddMember(mm);
                            }
                        }
                        else
                        {
                            if (miMono.MemberType != miMS.MemberType)
                            {
                                //AddMember (null, miMS);
                                //MissingMember mm2 = CreateMember (miMono, null);
                                //mm2.Status.AddWarning ("MemberType mismatch, is: '" + miMono.MemberType.ToString () + "' [should be: '" + miMS.MemberType.ToString ()+"']");
                                //AddMember (mm2);
                                mm.Status.AddWarning("MemberType mismatch, is: '" + miMono.MemberType.ToString() + "' [should be: '" + miMS.MemberType.ToString() + "']");
                                AddMember(mm);
                            }
                            else if (fVisibleMS || IsVisible(miMono))
                            {
                                AddMember(mm);
                            }

                            htMono.Remove(strNameUnique);
                        }

                        switch (miMS.MemberType)
                        {
                        case MemberTypes.Method:
                        {
                            string strNameMSFull = miMS.ToString();
                            int    ichMS         = strNameMSFull.IndexOf(' ');
                            string strNameMS     = strNameMSFull.Substring(ichMS + 1);
                            if (!htMethodsMS.Contains(strNameMS))
                            {
                                htMethodsMS.Add(strNameMSFull.Substring(ichMS + 1), miMS);
                            }
                            break;
                        }
                        }
                    }
                }
            }
            foreach (MemberInfo miMono in htMono.Values)
            {
                if (IsVisible(miMono))
                {
                    MissingMember mm = CreateMember(miMono, null);
                    switch (miMono.MemberType)
                    {
                    case MemberTypes.Method:
                    {
                        string     strNameMonoFull = miMono.ToString();
                        int        ichMono         = strNameMonoFull.IndexOf(' ');
                        string     strNameMono     = strNameMonoFull.Substring(ichMono + 1);
                        MemberInfo miMS            = (MemberInfo)htMethodsMS [strNameMono];
                        if (miMS != null)
                        {
                            string strNameMSFull     = miMS.ToString();
                            int    ichMS             = strNameMSFull.IndexOf(' ');
                            string strReturnTypeMS   = strNameMSFull.Substring(0, ichMS);
                            string strReturnTypeMono = strNameMonoFull.Substring(0, ichMono);
                            mm.Status.AddWarning("Return type mismatch, is: '" + strReturnTypeMono + "' [should be: '" + strReturnTypeMS + "']");
                            //Console.WriteLine ("WARNING: Return type mismatch on "+miMS.DeclaringType.FullName+"."+strNameMono+", is: '"+strReturnTypeMono+"' [should be: '"+strReturnTypeMS+"']");
                        }
                        break;
                    }
                    }
                    AddMember(mm);
                }
            }

            // compare the attributes
            rgAttributes = new ArrayList();
            nsAttributes = MissingAttribute.AnalyzeAttributes(
                (typeMono == null) ? null : typeMono.GetCustomAttributes(false),
                (typeMS == null) ? null :   typeMS.GetCustomAttributes(false),
                rgAttributes);

            rgInterfaces = new ArrayList();
            if (typeMono != null && typeMS != null)
            {
                // compare base types
                string strBaseMono = (typeMono.BaseType == null) ? null : typeMono.BaseType.FullName;
                string strBaseMS   = (typeMS.BaseType == null) ? null :   typeMS.BaseType.FullName;
                if (strBaseMono != strBaseMS)
                {
                    m_nodeStatus.AddWarning("Base class mismatch, is '" + strBaseMono + "' [should be: '" + strBaseMS + "']");
                    //Console.WriteLine ("WARNING: Base class mismatch on "+typeMono.FullName+", is: '"+strBaseMono+"' [should be: '"+strBaseMS+"']");
                }

                // compare the interfaces
                Hashtable htInterfacesMono = new Hashtable();
                Type []   rgInterfacesMono = typeMono.GetInterfaces();
                foreach (Type ifaceMono in rgInterfacesMono)
                {
                    if (ifaceMono != null)
                    {
                        string strName = ifaceMono.FullName;
                        htInterfacesMono.Add(strName, ifaceMono);
                    }
                }
                Type [] rgInterfacesMS = typeMS.GetInterfaces();
                foreach (Type ifaceMS in rgInterfacesMS)
                {
                    if (ifaceMS != null)
                    {
                        string           strName   = ifaceMS.FullName;
                        Type             ifaceMono = (Type)htInterfacesMono [strName];
                        MissingInterface mi        = new MissingInterface(ifaceMono, ifaceMS);
                        mi.Analyze();
                        rgInterfaces.Add(mi);
                        if (ifaceMono != null)
                        {
                            htInterfacesMono.Remove(strName);
                        }
                        nsInterfaces.AddChildren(mi.Status);
                    }
                }
                foreach (Type ifaceMono in htInterfacesMono.Values)
                {
                    MissingInterface mi = new MissingInterface(ifaceMono, null);
                    mi.Analyze();
                    rgInterfaces.Add(mi);
                    //Console.WriteLine ("WARNING: additional interface on "+typeMono.FullName+": '"+ifaceMono.FullName+"'");
                    nsInterfaces.AddChildren(mi.Status);
                }

                // 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
            m_nodeStatus.Add(nsAttributes);
            m_nodeStatus.Add(nsMethods);
            m_nodeStatus.Add(nsProperties);
            m_nodeStatus.Add(nsEvents);
            m_nodeStatus.Add(nsFields);
            m_nodeStatus.Add(nsConstructors);
            m_nodeStatus.Add(nsNestedTypes);
            m_nodeStatus.Add(nsInterfaces);

            return(m_nodeStatus);
        }