public RemoteResponse <AssembliesNamespacesClasses> GetClassEntityFromUserSelectedClass(string assemblyPath, bool isSilverlight, List <string> references) { var ancs = new AssembliesNamespacesClasses(); string targetProjectPath = Path.GetDirectoryName(assemblyPath); AssemblyDefinition targetAssemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath); Exception ex = null; var assembliesToLoad = new Hashtable(); // Load this assembly assembliesToLoad.Add(assemblyPath.ToLower(), null); foreach (var item in targetAssemblyDefinition.MainModule.AssemblyReferences) { if (item.IsNotMicrosoftAssembly()) { string assemblyFullPath = this.GetAssemblyFullPath(targetProjectPath, item.Name); if (assemblyFullPath.IsNotNullOrEmpty() && assembliesToLoad.ContainsKey(assemblyFullPath.ToLower()) == false) { assembliesToLoad.Add(assemblyFullPath.ToLower(), null); } } } // Load up all assemblies referenced in the project, but that are not // loaded yet. foreach (var name in references) { if (!assembliesToLoad.ContainsKey(Path.GetFileName(name.ToLower()))) { assembliesToLoad.Add(name.ToLower(), null); } } string failedAssemblies = string.Empty; var status = ResponseStatus.Failed; foreach (string assemblyToLoadPath in assembliesToLoad.Keys) { targetAssemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyToLoadPath); this.LoadAssemblyClasses(targetAssemblyDefinition, isSilverlight, ancs, out ex, assembliesToLoad); if (ex == null) { status = ResponseStatus.Success; continue; } failedAssemblies += String.Format("{0}{1}", targetAssemblyDefinition.Name, Environment.NewLine); // return new RemoteResponse<AssembliesNamespacesClasses>(null, ResponseStatus.Exception, ex, String.Format("Unable to load types from target assembly: {0}", targetAssemblyDefinition.Name)); } return(new RemoteResponse <AssembliesNamespacesClasses>(ancs, status, failedAssemblies)); }
public SelectClassFromAssembliesWindow(AssembliesNamespacesClasses assembliesNamespacesClasses, string nameOfSourceCommand) { // This call is required by the Windows Form Designer. InitializeComponent(); // Add any initialization after the InitializeComponent() call. var cvs = new CollectionViewSource(); _assemblyNamespaceClassCollectionView = CollectionViewSource.GetDefaultView(assembliesNamespacesClasses) as CollectionView; _assemblyNamespaceClassCollectionView.GroupDescriptions.Clear(); _assemblyNamespaceClassCollectionView.SortDescriptions.Clear(); _assemblyNamespaceClassCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("AssemblyName")); _assemblyNamespaceClassCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("Namespace")); _assemblyNamespaceClassCollectionView.SortDescriptions.Add(new SortDescription("AssemblyName", ListSortDirection.Ascending)); _assemblyNamespaceClassCollectionView.SortDescriptions.Add(new SortDescription("Namespace", ListSortDirection.Ascending)); _assemblyNamespaceClassCollectionView.SortDescriptions.Add(new SortDescription("TypeName", ListSortDirection.Ascending)); this.tvObjects.ItemsSource = _assemblyNamespaceClassCollectionView.Groups; this.tbCommandCaption.Text = string.Concat("For ", nameOfSourceCommand); }
private void LoadAssemblyClasses(AssemblyDefinition assemblyDefinition, bool isSilverlight, AssembliesNamespacesClasses ancs, out Exception exOut, Hashtable assembliesToLoad) { exOut = null; try { foreach (var type in assemblyDefinition.MainModule.Types) { if (type.IsPublic && type.IsClass && !type.IsAbstract && !type.Name.Contains("<Module>") && !type.Name.Contains("AnonymousType") && !type.Name.StartsWith("_") && !type.Name.EndsWith("AssemblyInfo")) { bool previouslyLoaded = false; foreach (var anc in ancs) { if (type.Name != anc.TypeName || type.Namespace != anc.Namespace || assemblyDefinition.Name.Name != anc.AssemblyName) { continue; } previouslyLoaded = true; break; } if (!previouslyLoaded) { if (type.BaseType == null || type.BaseType.Name != "MulticastDelegate") { var classEntity = new ClassEntity(type.Name, isSilverlight); foreach ( var property in this.GetAllPropertiesForType(assemblyDefinition, type, assembliesToLoad)) { if (property.GetMethod != null && property.GetMethod.IsPublic) { var propertyInfo = new PropertyInformation(this.CanWrite(property), property.Name, this.FormatPropertyTypeName(property), property.PropertyType.Namespace); // BMK Test the logic of this line. // I'm not sure about the Type handling here. JGYO // var result1 = property.PropertyType is GenericInstanceType; // var result2 = property.PropertyType.GetType() == typeof(GenericInstanceType); var git = property.PropertyType as GenericInstanceType; if (git != null) { if (git.HasGenericArguments) { foreach (var typeRef in git.GenericArguments) { propertyInfo.GenericArguments.Add(typeRef.Name); } } } if (property.HasParameters) { foreach (var parameter in property.Parameters) { propertyInfo.PropertyParameters.Add(new PropertyParameter( parameter.Name, parameter.ParameterType.Name)); } } classEntity.PropertyInformation.Add(propertyInfo); } } ancs.Add(new AssembliesNamespacesClass(assemblyDefinition.Name.Name, type.Namespace, type.Name, classEntity)); } } } } } catch (Exception ex) { exOut = ex; } }