public void Get_All_Public_Fields() { var query = new FieldQuery("public * *"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(3, matches.Count, "Field count"); }
public void Get_All_NotPublic_Static_Fields() { var query = new FieldQuery("!public static * *"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(2, matches.Count, "Field Count"); }
public void Get_All_Fields() { var query = new FieldQuery(); var fields = query.GetMatchingFields(myFieldClass); Assert.AreEqual(14, fields.Count, "Field Count"); }
public void Get_All_GenericFields() { var query = new FieldQuery(" *> *"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(2, matches.Count, "Field count"); }
public void Get_All_ProtectedInternal_Fields() { var query = new FieldQuery("protected internal * *"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(3, matches.Count, "Field count"); }
public void Get_Public_Static_Fields_With_Partial_Field_Name() { var query = new FieldQuery("public static * *Staticint"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(1, matches.Count, "Field Count"); Assert.AreEqual("publicReadOnlyStaticint", matches[0].Name, "Field Name"); }
public void Get_Public_Static_Fields_With_Partial_Type_Name() { var query = new FieldQuery("public static *Tim* *"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(1, matches.Count, "Field Count"); Assert.AreEqual("publicStaticDateTimeField", matches[0].Name, "Field Name"); }
public void Get_All_Static_Readonly_Fields() { var query = new FieldQuery("static readonly * *"); var matches = query.GetMatchingFields(myFieldClass); Assert.AreEqual(2, matches.Count, "Field count"); Assert.AreEqual("protectedstaticreadonlyField", matches[0].Name, "Field name"); }
public void Get_All_Not_Const_Fields() { var query = new FieldQuery("!const * *"); var matches = query.GetMatchingFields(myFieldClass); try { Assert.AreEqual(10, matches.Count, "Field Count"); } finally { foreach (var field in matches) { Console.WriteLine("Field: {0}", field.Print(FieldPrintOptions.All)); } } }
public void Get_All_NotReadOnly_NotProtected_Fields() { var query = new FieldQuery("!readonly !protected * *"); var matches = query.GetMatchingFields(myFieldClass); try { Assert.AreEqual(9, matches.Count, "Field Count"); } finally { foreach (var field in matches) { Console.WriteLine("Field: {0}", field.Print(FieldPrintOptions.All)); } } }
public WhoUsesType(UsageQueryAggregator aggregator, List <TypeDefinition> funcArgTypes) : base(aggregator) { using (var t = new Tracer(Level.L5, myType, "WhoUsesType")) { if (funcArgTypes == null) { throw new ArgumentNullException("funcArgTypes"); } this.mySearchArgTypes = funcArgTypes; foreach (var funcArgType in funcArgTypes) { t.Info("Adding search type {0}", new LazyFormat(() => funcArgType.Print())); this.myArgSearchTypeNames.Add(funcArgType.Name); this.Aggregator.AddVisitScope(funcArgType.Module.Assembly.Name.Name); new WhoAccessesField(aggregator, notConst.GetMatchingFields(funcArgType)); } } }
public override void Execute() { base.Execute(); if (!IsValid) { Help(); return; } if (ExtractAndValidateTypeQuery(myParsedArgs.TypeAndInnerQuery) == false) { return; } List <FieldDefinition> fieldsToSearch = new List <FieldDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (cecilAssembly, file) => { using (PdbInformationReader pdbReader = new PdbInformationReader(myParsedArgs.SymbolServer)) { foreach (var type in myTypeQueries.GetMatchingTypes(cecilAssembly)) { myFieldQuery.GetMatchingFields(type).ForEach( (field) => { var fileLine = pdbReader.GetFileLine((TypeDefinition)field.DeclaringType); Writer.PrintRow( "{0,-80}; {1,-50}; {2}; {3}", () => GetFileInfoWhenEnabled(fileLine.Key), type.Print(), field.Print(FieldPrintOptions.All), Path.GetFileName(file), fileLine.Key ); lock (this) { fieldsToSearch.Add(field); } }); } } }); List <FieldDefinition> nonConstFields = (from field in fieldsToSearch where !field.HasConstant select field).ToList(); if (nonConstFields.Count < fieldsToSearch.Count) { Out.WriteLine("Warning: It is not possible to track the usage of constant fields. Only non constant fields are considered in the search."); Out.WriteLine(" The only secure way is to search the source code for the constant field/s in question."); } if (nonConstFields.Count == 0) { Out.WriteLine("Error: No non constant fields are found which usage could be tracked"); } Writer.PrintRow("", null); Writer.PrintRow("", null); Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (cecilAssembly, file) => { using (UsageQueryAggregator agg = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoAccessesField(agg, nonConstFields); agg.Analyze(cecilAssembly); agg.MethodMatches.ForEach((result) => { Writer.PrintRow("{0,-80};{1,-40}; {2}; {3}; {4}; {5}; {6}", () => GetFileInfoWhenEnabled(result.SourceFileName), result.Match.DeclaringType.FullName, result.Match.Print(MethodPrintOption.Full), Path.GetFileName(file), result.Annotations.Reason, result.Annotations.Item, result.SourceFileName, result.LineNumber ); }); } }); }