コード例 #1
0
ファイル: Util.cs プロジェクト: dsgouda/buildtools
        public static List<ITypeDefinitionMember> FindRelatedMembers(ITypeDefinitionMember member, TypeIncluded includeType)
        {
            List<ITypeDefinitionMember> relatedMembers = new List<ITypeDefinitionMember>();
            Dictionary<uint, ITypeReference> participatingTypes = new Dictionary<uint, ITypeReference>();

            ITypeDefinition currentType = member.ContainingTypeDefinition;
            do
            {
                //
                // add the type
                //
                participatingTypes.Add(currentType.InternedKey, currentType);

                //
                // add any interfaces it implements that are part of the closure
                //
                foreach (ITypeReference iface in currentType.Interfaces)
                {
                    INamedTypeReference ifaceTemplate = Util.CanonicalizeTypeReference(iface);
                    // check the closure against the template type, but add 
                    // the specialized type to participatingTypes so that
                    // argument matching works
                    if (includeType(ifaceTemplate) &&
                        !participatingTypes.ContainsKey(iface.InternedKey))
                    {
                        // Should we add ifaceTemplate or iface?
                        participatingTypes.Add(iface.InternedKey, iface);
                    }
                }

                //
                // go up to the base type
                //
                currentType = TypeHelper.BaseClass(currentType);
            }
            while (currentType != null);

            foreach (ITypeReference type in participatingTypes.Values)
            {
                ITypeDefinitionMember relatedMember = FindRelatedMember(type, member);
                if (null != relatedMember)
                {
                    relatedMembers.Add(relatedMember);
                }
                // TODO: Review
                foreach (IMethodImplementation methodImpl in Util.CanonicalizeType(type).ExplicitImplementationOverrides)
                {
                    ITypeDefinitionMember implementingMethod = Util.CanonicalizeMember(methodImpl.ImplementingMethod);
                    ITypeDefinitionMember implementedMethod = Util.CanonicalizeMember(methodImpl.ImplementedMethod);
                    bool implementedTypeIncluded = includeType(Util.CanonicalizeType(implementedMethod.ContainingType));

                    if ((implementedMethod == member) ||
                        (implementingMethod == member && implementedTypeIncluded))
                    {
                        if (!relatedMembers.Contains(implementingMethod)) { relatedMembers.Add(implementingMethod); }
                        if (!relatedMembers.Contains(implementedMethod)) { relatedMembers.Add(implementedMethod); }
                    }
                }
            }

            return relatedMembers;
        }
コード例 #2
0
        public static List <ITypeDefinitionMember> FindRelatedMembers(ITypeDefinitionMember member, TypeIncluded includeType)
        {
            List <ITypeDefinitionMember>      relatedMembers     = new List <ITypeDefinitionMember>();
            Dictionary <uint, ITypeReference> participatingTypes = new Dictionary <uint, ITypeReference>();

            ITypeDefinition currentType = member.ContainingTypeDefinition;

            do
            {
                //
                // add the type
                //
                participatingTypes.Add(currentType.InternedKey, currentType);

                //
                // add any interfaces it implements that are part of the closure
                //
                foreach (ITypeReference iface in currentType.Interfaces)
                {
                    INamedTypeReference ifaceTemplate = Util.CanonicalizeTypeReference(iface);
                    // check the closure against the template type, but add
                    // the specialized type to participatingTypes so that
                    // argument matching works
                    if (includeType(ifaceTemplate) &&
                        !participatingTypes.ContainsKey(iface.InternedKey))
                    {
                        // Should we add ifaceTemplate or iface?
                        participatingTypes.Add(iface.InternedKey, iface);
                    }
                }

                //
                // go up to the base type
                //
                currentType = TypeHelper.BaseClass(currentType);
            }while (currentType != null);

            foreach (ITypeReference type in participatingTypes.Values)
            {
                ITypeDefinitionMember relatedMember = FindRelatedMember(type, member);
                if (null != relatedMember)
                {
                    relatedMembers.Add(relatedMember);
                }
                // TODO: Review
                foreach (IMethodImplementation methodImpl in Util.CanonicalizeType(type).ExplicitImplementationOverrides)
                {
                    ITypeDefinitionMember implementingMethod = Util.CanonicalizeMember(methodImpl.ImplementingMethod);
                    ITypeDefinitionMember implementedMethod  = Util.CanonicalizeMember(methodImpl.ImplementedMethod);
                    bool implementedTypeIncluded             = includeType(Util.CanonicalizeType(implementedMethod.ContainingType));

                    if ((implementedMethod == member) ||
                        (implementingMethod == member && implementedTypeIncluded))
                    {
                        if (!relatedMembers.Contains(implementingMethod))
                        {
                            relatedMembers.Add(implementingMethod);
                        }
                        if (!relatedMembers.Contains(implementedMethod))
                        {
                            relatedMembers.Add(implementedMethod);
                        }
                    }
                }
            }

            return(relatedMembers);
        }