public virtual bool ExtractAndValidateTypeQuery(string query) { Match m = new Regex(@" *(?<typeName>.*?) *\( *(?<innerQuery>.*) *\) *").Match(query); if (m.Success) { myTypeQueries = TypeQuery.GetQueries(m.Groups["typeName"].Value, TypeQueryMode.All); myInnerQuery = m.Groups["innerQuery"].Value; return(true); } else { int opening = CountChars('(', query); int closing = CountChars(')', query); if (opening == 0) { Out.WriteLine("The query should contain at least one opening brace"); } else if (opening - closing != 0) { Out.WriteLine("The query {0} has not all braces closed.", query); } return(false); } }
public override void Execute() { base.Execute(); if (!IsValid) { Out.WriteLine("Expected: ApiChange -whousesType [typeQuery] [files] -in [files]"); Help(); return; } var typeQueries = TypeQuery.GetQueries(myParsedArgs.TypeQuery, TypeQueryMode.All); List <TypeDefinition> searchTypes = new List <TypeDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (cecilAssembly, file) => { using (var pdbReader = new PdbInformationReader(myParsedArgs.SymbolServer)) { foreach (TypeDefinition matchingType in typeQueries.GetMatchingTypes(cecilAssembly)) { var fileline = pdbReader.GetFileLine(matchingType); lock (this) { Writer.PrintRow("{0}; {1}; {2}", () => GetFileInfoWhenEnabled(fileline.Key), matchingType.Print(), Path.GetFileName(file), fileline.Key); searchTypes.Add(matchingType); } } } }); if (searchTypes.Count == 0) { Out.WriteLine("Error: Could not find any matching types to search for. Aborting"); return; } Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (cecilAssembly, file) => { using (UsageQueryAggregator agg = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoUsesType(agg, searchTypes); string fileName = Path.GetFileName(file); agg.Analyze(cecilAssembly); /* * "Assembly" "Type", "Method" "Field" "Match Reason" "Match Item" * "Source File" "Line" */ lock (this) { foreach (var match in agg.MethodMatches) { Writer.PrintRow("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", () => GetFileInfoWhenEnabled(match.SourceFileName), fileName, ((TypeDefinition)match.Match.DeclaringType).Print(), match.Match.Print(MethodPrintOption.Full), "", match.Annotations.Reason, match.Annotations.Item, match.SourceFileName, match.LineNumber); } foreach (var match in agg.TypeMatches) { Writer.PrintRow("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", () => GetFileInfoWhenEnabled(match.SourceFileName), fileName, match.Match.Print(), "", "", match.Annotations.Reason, match.Annotations.Item, match.SourceFileName, ""); } foreach (var match in agg.FieldMatches) { Writer.PrintRow("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", () => GetFileInfoWhenEnabled(match.SourceFileName), fileName, ((TypeDefinition)match.Match.DeclaringType).Print(), "", match.Match.Print(FieldPrintOptions.All), match.Annotations.Reason, match.Annotations.Item, match.SourceFileName, ""); } } } }); }
public override void Execute() { base.Execute(); if (!IsValid) { Help(); return; } var typeQueries = TypeQuery.GetQueries(myParsedArgs.TypeQuery, TypeQueryMode.Interface | TypeQueryMode.Public | TypeQueryMode.Internal); List <TypeDefinition> searchInterfaces = new List <TypeDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (itfAssembly, file) => { foreach (TypeDefinition matchingItf in typeQueries.GetMatchingTypes(itfAssembly)) { Writer.PrintRow("{0}; {1}", null, matchingItf.Print(), Path.GetFileName(file) ); lock (searchInterfaces) { searchInterfaces.Add(matchingItf); } } }); if (searchInterfaces.Count == 0) { Out.WriteLine("No Interfaces found. Aborting query."); return; } Writer.PrintRow("", null); Writer.PrintRow("", null); Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (implAssembly, file) => { using (UsageQueryAggregator agg = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoImplementsInterface(agg, searchInterfaces); agg.Analyze(implAssembly); foreach (var match in agg.TypeMatches) { Writer.PrintRow("{0,-60}; {1,-60}; {2}; {3}", () => GetFileInfoWhenEnabled(match.SourceFileName), match.Match.Print(), Path.GetFileName(file), match.Annotations.Item, match.SourceFileName); } } }); }