コード例 #1
0
        internal void GenerateMethodGraph(List <Assembly> assembliesToAnalyze)
        {
            assembliesToAnalyze.AddRange(_plugins.SelectMany(p => p.ListOtherFoundAssemblies()));

            _graph = new TypeFriendlyDictionary <Type, TypeFriendlyDictionary <MethodBase, bool> >();
            foreach (var assembly in assembliesToAnalyze)
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.FullName.Contains("<"))
                    {
                        continue;                         // skip anonymous types
                    }
                    var degenericedType = DegenerifyType(type);
                    _graph.Add(degenericedType, new TypeFriendlyDictionary <MethodBase, bool>());
                    UnusedMethods.Add(type, new List <MethodBase>());
                    if (!degenericedType.IsInterface)
                    {
                        TrackInterfaceImplementations(degenericedType);
                    }
                    TrackMethodUsage(degenericedType);
                    _unusedClasses.Add(degenericedType, false);
                }
            }
        }
コード例 #2
0
        internal void FinalizeReport()
        {
            UnusedClasses = _plugins
                            .Select(p => (Func <IEnumerable <Type>, IEnumerable <Type> >)p.FilterUnusedTypes)
                            .Aggregate(_unusedClasses.Keys.AsEnumerable(), (s, f) => f(s), f => f)
                            .ToList();


            var newUnusedMethods = new TypeFriendlyDictionary <Type, List <MethodBase> >();
            var plugins          = _plugins.Select(p => (Func <IEnumerable <MethodBase>, IEnumerable <MethodBase> >)p.FilterUnusedMethods).ToList();

            foreach (var entry in UnusedMethods)
            {
                newUnusedMethods.Add(entry.Key, plugins
                                     .Aggregate(entry.Value.AsEnumerable(), (s, f) => f(s), f => f)
                                     .ToList());
            }
        }