/// <summary> /// /// </summary> /// <param name="assemblyName">Name to give the virtual assembly (for cstsd purposes).</param> public RoslynTypeScanner(string assemblyName) { NetAssembly = new NetAssembly { Name = assemblyName }; }
public void AddAssembly(string filePath) { Tracer.Verbose("AssemblyExplorer:AddAssembly", "Parsing the file {0}", filePath); try { using (new LongOperation(this, "Parsing the assembly")) { IAssemblyParser parser = AssemblyParserFactory.GetParser(eParserType.NetParser); NetAssembly ass = parser.LoadAssemblyRecursively(filePath); // net assembly or parsing ok if (ass != null) { BindingView.Instance.Workspace.Assemblies.Add(ass); treeViewAss.AddItem(null, ass.Name, ass); } } } catch (Exception err) { Tracer.Error("AssemblyExplorer.AddAssembly", err); } finally { Tracer.Verbose("AssemblyExplorer:AddAssembly", "END"); } }
/// <summary> /// Add all needed types of this assembly into the list /// </summary> /// <param name="asm"></param> /// <param name="mapList"></param> private void AddAssemblyMap(NetAssembly asm, List <MethodMapInfo> mapList) { Tracer.Verbose("MethodMapBuilder.AddAssemblyMap", asm.Name); try { foreach (NetClass classTyp in asm.Children) { foreach (NetMethod methodType in classTyp.Children) { methodType.Handle = _HandleCounter++; mapList.Add ( new MethodMapInfo() { Handle = methodType.Handle, Method = methodType.DisplayName, Namespace = classTyp.Name } ); Tracer.Verbose("MethodMapBuilder.AddAssemblyMap / Add type ==> ", methodType.Name); } } } catch (Exception error) { Tracer.Error("MethodMapBuilder.AddAssemblyMap", error); } }
public NetType ScanType(TypeDefinition type, NetAssembly assembly) { Logger.LogTrace(" Scanning type '{0}'", type.Name); var typeModel = Factory.CreateTypeModel(type); typeModel.Type = GetTypeClass(type); typeModel.Assembly = assembly; typeModel.Visibility = GetVisibility(type); typeModel.IsStatic = IsStatic(type); typeModel.IsAbstract = IsAbstract(type); typeModel.IsSealed = IsSealed(type); typeModel.GenericTypeArgs = CreateGenericTypeArgs(type); typeModel.Methods = CreateMethods(type, typeModel); typeModel.Properties = CreateProperties(type, typeModel); typeModel.Fields = CreateFields(type, typeModel); typeModel.DisplayName = GetDisplayName(typeModel); typeModel.Implements = GetImplementedInterfaces(type); typeModel.Exports = GetMefUsedInterfaces(type, nameof(AttributeType.Export)); typeModel.Imports = GetMefUsedInterfaces(type, nameof(AttributeType.Import)); typeModel.Attributes = GetAttributes(type); typeModel.BaseType = GetBaseType(type); return(typeModel); }
private IList <NetType> CreateTypes(NetAssembly assembly) { var typeScanner = new TypeScanner(Module, Factory, Logger); return(Module.Types .Where(IncludeType) .Select(type => typeScanner.ScanType(type, assembly)) .ToList()); }
private void ConnectAssemblyReferences(NetAssembly assembly) { _logger.LogInformation("Connecting assembly references for '{0}'", assembly.Name); foreach (var reference in assembly.References) { _tx.CreateRelationship(assembly, reference, Relationship.DEPENDS_ON); } }
private NetClass AddClass(NetAssembly assembly, TypeDefinition modulType) { return(new NetClass(modulType) { Name = modulType.Name, BaseType = new NetBaseType(modulType.BaseType), NameSpace = modulType.Namespace, Parent = assembly }); }
/// <summary> /// Load all object in the given assembly /// </summary> /// <param name="assemblyPath"></param> /// <returns></returns> public NetAssembly LoadAssemblyRecursively(string assemblyPath) { NetAssembly ass = LoadAssembly(assemblyPath); //load the references ass.References = GetAssemblyReferences(ass); //load the type in the assembly ass.Children = GetAssemblyTypesRecursively(ass); return(ass); }
private void ConnectTypes(NetAssembly assembly) { _logger.LogInformation("Connecting types for assembly '{0}'", assembly.Name); foreach (var type in assembly.DefinedTypes) { ConnectTypeDefinitions(assembly, type); ConnectBaseType(type); ConnectInterfaceImplementations(type); ConnectMethods(type); ConnectAttributes(type); } }
public void SetupScanner() { _scanner = new MethodScanner(Module, ModelFactory, Logger); var assembly = new NetAssembly { Name = "TestLibrary" }; var typeScanner = new TypeScanner(Module, ModelFactory, Logger); typeScanner.ScanType(GetTypeDefintion <ClassWithMembers>(), assembly); typeScanner.ScanType(GetTypeDefintion <InheritedFromClassWithMembers>(), assembly); }
/// <summary> /// Load the references of the given assembly /// </summary> /// <param name="assembly"></param> /// <returns></returns> public ObservableCollection <NetReference> GetAssemblyReferences(NetAssembly assembly) { ObservableCollection <NetReference> list = new ObservableCollection <NetReference>(); foreach (AssemblyName assemblyName in ((Assembly)assembly.Tag).GetReferencedAssemblies()) { list.Add(new NetReference(assemblyName) { Parent = assembly, Name = assemblyName.Name }); } return(list); }
/// <summary> /// Load the references of the given assembly /// </summary> /// <param name="assembly"></param> /// <returns></returns> public ObservableCollection <NetReference> GetAssemblyReferences(NetAssembly assembly) { ObservableCollection <NetReference> list = new ObservableCollection <NetReference>(); foreach (ModuleDefinition mod in ((AssemblyDefinition)assembly.Tag).Modules) { foreach (AssemblyNameReference assRef in mod.AssemblyReferences) { list.Add(new NetReference(assRef) { Name = assRef.Name }); } } return(list); }
/// <summary> /// Load all the type in the given assembly /// </summary> /// <param name="assembly"></param> /// <returns></returns> public ObservableCollection <BindableObjectExtended> GetAssemblyTypes(NetAssembly assembly) { ObservableCollection <BindableObjectExtended> list = new ObservableCollection <BindableObjectExtended>(); //load the type in the assembly foreach (TypeDefinition modulType in ((AssemblyDefinition)assembly.Tag).MainModule.Types) { if (modulType.Name == CecilHelper.CecilModul) { continue; } if (modulType.IsClass && !modulType.IsEnum) { list.Add(AddClass(assembly, modulType)); } } return(list); }
/// <summary> /// Refresh an assembly and all subtypes if loaded /// </summary> /// <param name="assembly"></param> public void RefreshAssembly(NetAssembly assembly) { //reload cecil assembly definition assembly.Tag = CecilHelper.GetAssembly(assembly.FilePath); //for each type in cecil assembly, refresh or load it foreach (TypeDefinition modulType in ((AssemblyDefinition)assembly.Tag).MainModule.Types) { if (modulType.Name == CecilHelper.CecilModul) { continue; } if (modulType.IsClass) { if (!RefreshClass(assembly.Children, modulType)) { AddClass(assembly, modulType); } } } }
/// <summary> /// Load all the type in the given assembly /// </summary> /// <param name="assembly"></param> /// <returns></returns> public ObservableCollection <BindableObjectExtended> GetAssemblyTypes(NetAssembly assembly) { ObservableCollection <BindableObjectExtended> list = new ObservableCollection <BindableObjectExtended>(); foreach (Type typ in ((Assembly)assembly.Tag).GetTypes()) { // get the namespace from the types if (assembly.Namespaces.Where(p => p.Name == typ.Namespace).Count() == 0) { assembly.Namespaces.Add(new NetNamespace(null) { Parent = assembly, Name = typ.Namespace }); } if (typ.IsClass) { list.Add(new NetClass(typ) { Name = typ.Name, BaseType = new NetBaseType(typ.BaseType), NameSpace = typ.Namespace }); } else if (typ.IsInterface) { list.Add(new NetInterface(typ) { Name = typ.Name, NameSpace = typ.Namespace }); } } return(list); }
public void SetupScanner() { _assembly = NetAssembly("TestLibrary"); _scanner = new TypeScanner(Module, ModelFactory, Logger); }
private void ConnectTypeDefinitions(NetAssembly assembly, NetType type) { _db.CreateRelationship(assembly, type, Relationship.DEFINES_TYPE); }
/// <summary> /// /// </summary> /// <param name="AsmToProfile"></param> /// <param name="context"></param> /// <returns></returns> private void ProfileAssembly(NetAssembly AsmToProfile) { Tracer.Verbose("InjectionProfiler.ProfileAssembly START ", AsmToProfile.Name); PrepareContext(); try { AssemblyDefinition CecilAssDefinition = (AssemblyDefinition)AsmToProfile.Tag; // add a build tag class so we know later if already built CecilAssDefinition.MainModule.Types.Add(_Context.TagType); //add the runtime spy reference CecilAssDefinition.MainModule.AssemblyReferences.Add(_Context.SpyAsmNameReference); //get back the reference of enter method _Context.StartMethodRef = CecilAssDefinition.MainModule.Import(_Context.StartMethodInfo); _Context.EndMethodRef = CecilAssDefinition.MainModule.Import(_Context.EndMethodInfo); _Context.StartEndMethodRef = CecilAssDefinition.MainModule.Import(_Context.StartEndMethodInfo); //for each type we get in our tree foreach (NetClass classTyp in AsmToProfile.Children) { //if need to be profiled if (classTyp.IsChecked == true) { Tracer.Info("InjectionProfiler.ProfileAssembly", string.Format(Resources.CORE_PROFILING_CLASS, classTyp.Name)); foreach (NetMethod methodType in classTyp.Children) { if (methodType.IsChecked == true) { this.PrepareMethod(CecilAssDefinition, methodType); } } CecilAssDefinition.MainModule.Import((TypeDefinition)classTyp.Tag); } if (CancelPending()) { return; } } // TODO // gestion chemin string ProfiledFilePath = Path.Combine(Project.SubFolderProfiled, new FileInfo(AsmToProfile.FilePath).Name); //call cecil to save it AssemblyFactory.SaveAssembly(CecilAssDefinition, ProfiledFilePath); Tracer.Info("InjectionProfiler.ProfileAssembly", string.Format(Resources.CORE_PROFILING_SAVE, AsmToProfile.Name)); } catch (Exception error) { Tracer.Error("InjectionProfiler:ProfileAssembly", error); Result = false; } finally { Tracer.Verbose("InjectionProfiler.ProfileAssembly END", AsmToProfile.Name); } }
/// <summary> /// Load all the types and subtypes in the given assembly /// </summary> /// <param name="assembly"></param> /// <returns></returns> public ObservableCollection <BindableObjectExtended> GetAssemblyTypesRecursively(NetAssembly assembly) { ObservableCollection <BindableObjectExtended> list = new ObservableCollection <BindableObjectExtended>(); list = GetAssemblyTypes(assembly); //load type methods foreach (NetBaseType typ in list) { typ.Children = (ObservableCollection <BindableObjectExtended>)GetMembers(typ); } return(list); }
/// <summary> /// Refresh an assembly and all subtypes if loaded /// </summary> /// <param name="assembly"></param> public void RefreshAssembly(NetAssembly assembly) { }