diff --git a/Compiler/Analyzers/DeadCodeAnalyzer/Configuration.cs b/Compiler/Analyzers/DeadCodeAnalyzer/Configuration.cs index fde372003..3138fccae 100644 --- a/Compiler/Analyzers/DeadCodeAnalyzer/Configuration.cs +++ b/Compiler/Analyzers/DeadCodeAnalyzer/Configuration.cs @@ -9,7 +9,8 @@ public class Configuration { private readonly bool _DeadCodeElimination; private readonly bool _NonAggressiveVirtualMethodElimination; private readonly IList _WhiteList; - + private readonly IList _AssembliesWhiteList; + public Configuration(IDictionary configuration) { _DeadCodeElimination = configuration.ContainsKey("DeadCodeElimination") && configuration["DeadCodeElimination"] is bool && @@ -23,6 +24,11 @@ public Configuration(IDictionary configuration) { configuration["WhiteList"] is IList) { _WhiteList = ((IList) configuration["WhiteList"]).Cast().ToList(); } + + if (configuration.ContainsKey("AssembliesWhiteList") && configuration["AssembliesWhiteList"] is IList) + { + _AssembliesWhiteList = ((IList)configuration["AssembliesWhiteList"]).Cast().ToList(); + } } public bool DeadCodeElimination @@ -39,5 +45,10 @@ public IList WhiteList { get { return _WhiteList; } } + + public IList AssembliesWhiteList + { + get { return _AssembliesWhiteList; } + } } } diff --git a/Compiler/Analyzers/DeadCodeAnalyzer/DeadCodeInfoProvider.cs b/Compiler/Analyzers/DeadCodeAnalyzer/DeadCodeInfoProvider.cs index 47b35c6e6..5d6419aae 100644 --- a/Compiler/Analyzers/DeadCodeAnalyzer/DeadCodeInfoProvider.cs +++ b/Compiler/Analyzers/DeadCodeAnalyzer/DeadCodeInfoProvider.cs @@ -117,6 +117,7 @@ public bool IsIncluded(TypeDefinition typeToTest) private readonly HashSet Events = new HashSet(); private readonly TypeMapStep TypeMapStep = new TypeMapStep(); + private readonly List AssembliesWhiteListCache; private readonly List WhiteListCache; private readonly Configuration Configuration; @@ -130,6 +131,16 @@ public DeadCodeInfoProvider(Configuration configuration) { WhiteListCache.Add(compiledRegex); } } + + if (configuration.AssembliesWhiteList != null && configuration.AssembliesWhiteList.Count > 0) + { + AssembliesWhiteListCache = new List(configuration.AssembliesWhiteList.Count); + foreach (var pattern in configuration.AssembliesWhiteList) + { + var compiledRegex = new Regex(pattern, RegexOptions.ECMAScript | RegexOptions.Compiled); + AssembliesWhiteListCache.Add(compiledRegex); + } + } } internal TypeInfoProvider TypeInfoProvider { get; set; } @@ -892,6 +903,14 @@ private void AddField(FieldReference field) { private bool IsMemberWhiteListed(MemberReference member) { + if (AssembliesWhiteListCache != null) + { + if (AssembliesWhiteListCache.Any(regex => regex.IsMatch(member.Module.Assembly.FullName))) + { + return true; + } + } + if (WhiteListCache != null) { if (WhiteListCache.Any(regex => regex.IsMatch(member.FullName))) { return true;