Ejemplo n.º 1
0
        internal HashSet <IMemberData> FindUsedMembers(IEnumerable <IMemberData> rootMembers, IEnumerable <IMemberData> members, ISelectionContext context)
        {
            var memberSet   = members.ToSet();
            var assemblySet = memberSet.Select(m => m.Assembly)
                              .Distinct()
                              .ToSet();

            var methodsByBases = members.OfType <MethodData>().SelectMany(
                method => from baseMethod in method.GetOverridesAndImplements()
                where context.Types.Contains(baseMethod.DeclaringType)
                select new {
                BaseMethod = baseMethod,
                Method     = method
            }
                ).ToLookup(
                x => x.BaseMethod,
                x => x.Method
                );

            var usedMembers = rootMembers.Union(
                configuration.DefinitelyUsed.SelectFrom(members, context)
                ).ToArray();

            var collector = new UsedMemberCollector(
                usedMembers, member => assemblySet.Contains(this.GetDeclaringAssembly(member)), methodsByBases
                );

            collector.CollectAll();

            var result = collector.Collected;

            result.IntersectWith(memberSet);

            return(result);
        }
Ejemplo n.º 2
0
        internal HashSet<IMemberData> FindUsedMembers(IEnumerable<IMemberData> rootMembers, IEnumerable<IMemberData> members, ISelectionContext context)
        {
            var memberSet = members.ToSet();
            var assemblySet = memberSet.Select(m => m.Assembly)
                                       .Distinct()
                                       .ToSet();

            var methodsByBases = members.OfType<MethodData>().SelectMany(
                method => from baseMethod in method.GetOverridesAndImplements()
                          where context.Types.Contains(baseMethod.DeclaringType)
                          select new {
                              BaseMethod = baseMethod,
                              Method = method
                          }
            ).ToLookup(
                x => x.BaseMethod,
                x => x.Method
            );

            var usedMembers = rootMembers.Union(
                configuration.DefinitelyUsed.SelectFrom(members, context)
            ).ToArray();

            var collector = new UsedMemberCollector(
                usedMembers, member => assemblySet.Contains(this.GetDeclaringAssembly(member)), methodsByBases
            );
            collector.CollectAll();

            var result = collector.Collected;
            result.IntersectWith(memberSet);

            return result;
        }