internal static void AnalyzeReferences() { ModuleDefinition md; foreach (var bf in LocalData.BlazorFilesList) { md = ModuleDefinition.ReadModule(bf.FI.FullName); if (md.HasAssemblyReferences) { foreach (var item in md.AssemblyReferences) { if (File.Exists(Path.Combine(bf.FI.Directory.FullName, item.Name + ".dll"))) { if (LocalData.BlazorFilesList.Any(x => x.FI.Name.Equals(item.Name + ".dll"))) { BlazorFile tmp = LocalData.BlazorFilesList.Single(x => x.FI.Name.Equals(item.Name + ".dll")); bf.References.Add(tmp); if (!tmp.Usings.Any(x => x == bf)) { tmp.Usings.Add(bf); } } } } } md.Dispose(); } foreach (var item in LocalData.BlazorFilesList) { foreach (var i in item.Usings) { Console.WriteLine(item.FI.Name + " is used by " + i.FI.Name); } } if (LocalData.BlazorFilesList.Count(x => x.Usings.Count == 0) == 1) { LocalData.BlazorFilesList.First(x => x.Usings.Count == 0).IsPrimary = true; Console.WriteLine(Environment.NewLine + "Primary file is " + LocalData.BlazorFilesList.First(x => x.Usings.Count == 0).FI.Name); } else { throw new Exception("Can't determine primary file"); } }
public static bool HasReference(BlazorFile bf, bool LookingInsideParentModule, string Name, string TypeName = "") { string tmpName = Name; //Console.WriteLine(Environment.NewLine + "Looking in " + bf.Name + " name " + Name +" " +LookingInsideParentModule); foreach (var t in bf.module.GetTypes()) { // if (LookingInsideParentModule) { if (string.IsNullOrEmpty(TypeName)) { tmpName = Name; } else { if (t.Name.Equals(TypeName)) { tmpName = Name; } else { List <string> tmp_list = GetInheritanceForSameModule(t, new List <string>()); //if (tmp_list.Any()) //{ // Console.WriteLine(Environment.NewLine + "abc " + Name +" "+ TypeName); // Console.WriteLine("Class inheritance for " + t.Name); // foreach (var item in tmp_list) // { // Console.WriteLine("===" + item); // } // Console.WriteLine(Environment.NewLine); //} if (tmp_list.Any(x => x.Equals(TypeName))) { tmpName = Name; } else { tmpName = TypeName + "::" + Name; } } } } else { tmpName = Name; } //foreach (var item in t.Methods.Where(p => p.HasBody)) //{ // foreach (var it in item.Body.Instructions.Where(x=>x.ToString().Contains(Name))) // { // Console.WriteLine(it.ToString()); // } //} //if (Name == "test11") //{ // IEnumerable<Instruction> aaa = t.Methods.Where(p => p.HasBody) // .SelectMany(p => p.Body.Instructions.Where(x => x.ToString().Contains("test11"))); // foreach (var item in aaa) // { // Console.WriteLine(item.ToString()); // // Console.WriteLine(item.Operand.ToString()); // //Console.WriteLine(item.Operand. .ToString() + " " + Name); // } //} IEnumerable <Instruction> a = t.Methods.Where(p => p.HasBody) .SelectMany(p => p.Body.Instructions.Where(x => x.ToString().Contains(tmpName))); //IEnumerable<Instruction> a = t.Methods.Where(p => p.HasBody) // .SelectMany(p => p.Body.Instructions.Where(i => i.OpCode.Code == Code.Call && // ((MethodReference)i.Operand).DeclaringType.FullName.Contains(Name))); //foreach (var item in a) //{ // Console.WriteLine(item.ToString()); // // Console.WriteLine(item.Operand.ToString()); // //Console.WriteLine(item.Operand. .ToString() + " " + Name); //} if (a.Count() > 0) { return(true); } } return(false); }