public AssemblyViewModel(AssemblyInfo assemblyInfo, IEnumerable<TypeViewModel> types)
        {
            _assemblyInfo = assemblyInfo;
            _types = types;

            foreach (var type in _types)
            {
                type.Assembly = this;
            }
        }
        private AssemblyViewModel(AssemblyInfo assembly)
        {
            _assembly = assembly;
            _correspondence.Add(assembly, this);
            foreach (var assemblyInfo in _assembly.ReferencedAssemblies)
            {
                _referencedAssemblies.Add(Create(assemblyInfo));
            }

            ToggleSelectionCommand = new DelegateCommand(ToggleSelectionCommandHandler);
        }
        public AssemblyViewModel(AssemblyInfo assemblyInfo, 
								 AssemblyBrowserWindowViewModel windowViewModel)
        {
            _assemblyInfo = assemblyInfo;
            _windowViewModel = windowViewModel;

            var types = _assemblyInfo.Modules
                .SelectMany(m => m.Types);
            _exportedTypesCount = assemblyInfo.ExportedTypesCount;
            _internalTypesCount = assemblyInfo.InternalTypesCount;

            RemoveCommand = new DelegateCommand(RemoveCommandHandler);

            RefreshForeground();
        }
Esempio n. 4
0
        public AssemblyInfo Assembly(object assembly)
        {
            if (assembly == null)
            {
                return null;
            }

            var assemblyDefinition = assembly as IAssembly;

            if (_assemblyCorrespondence.ContainsKey(assemblyDefinition))
            {
                return _assemblyCorrespondence[assemblyDefinition];
            }

            var typeDefinitions = assemblyDefinition.Modules
                .OfType<IModule>()
                .SelectMany(GetTypeDeclarations)
                .Distinct()
                .ToArray();

            string publicKeyToken;
            if (assemblyDefinition.PublicKeyToken == null || assemblyDefinition.PublicKeyToken.Length == 0)
            {
                publicKeyToken = "null";
            }
            else
            {
                var builder = new StringBuilder();
                for (int i = 0; i < assemblyDefinition.PublicKeyToken.Length; i++)
                {
                    builder.Append(assemblyDefinition.PublicKeyToken[i].ToString("x2"));
                }
                publicKeyToken = builder.ToString();
            }

            var culture = string.IsNullOrWhiteSpace(assemblyDefinition.Culture) ? "neutral" : assemblyDefinition.Culture;

            var fullName = string.Format("{0}, Version={1}, Culture={2}, PublicKeyToken={3}",
                assemblyDefinition.Name, assemblyDefinition.Version.ToString(4), culture, publicKeyToken);

            var assemblyInfo = new AssemblyInfo
            {
                Name = assemblyDefinition.Name,
                FullName = fullName,
                ExportedTypesCount = typeDefinitions.Count(
                    t => t.Visibility == TypeVisibility.Public
                         || t.Visibility == TypeVisibility.NestedPublic
                         || t.Visibility == TypeVisibility.NestedFamilyOrAssembly
                         || t.Visibility == TypeVisibility.NestedFamily),
                InternalTypesCount = typeDefinitions.Count(
                    t => t.Visibility == TypeVisibility.Private
                         || t.Visibility == TypeVisibility.NestedPrivate
                         || t.Visibility == TypeVisibility.NestedFamilyAndAssembly
                         || t.Visibility == TypeVisibility.NestedAssembly),
                Version = assemblyDefinition.Version
            };

            _assemblyCorrespondence.Add(assemblyDefinition, assemblyInfo);
            assemblyInfo.Modules = assemblyDefinition.Modules.OfType<IModule>().Select(m => Module(m)).ToArray();
            foreach (var module in assemblyInfo.Modules)
            {
                if (module.Assembly == null)
                {
                    module.Assembly = assemblyInfo;
                }
            }

            assemblyInfo.ReferencedAssemblies = assemblyDefinition.Modules
                .OfType<IModule>()
                .SelectMany(m => m.AssemblyReferences.OfType<IAssemblyReference>()
                    .Select(r => r.Resolve())
                    .Where(ad => ad != null)
                    .Select(ad => Assembly(ad)));

            return assemblyInfo;
        }
 public static AssemblyViewModel Create(AssemblyInfo assemblyInfo)
 {
     if (_correspondence.ContainsKey(assemblyInfo))
     {
         return _correspondence[assemblyInfo];
     }
     return new AssemblyViewModel(assemblyInfo);
 }
 public void RemoveAssembly(AssemblyInfo assemblyDefinition)
 {
     var assemblyViewModel = _assemblies
         .FirstOrDefault(vm => vm.AssemblyInfo == assemblyDefinition);
     if (assemblyViewModel != null)
     {
         _assemblies.Remove(assemblyViewModel);
         OnAssembliesChanged();
     }
 }
        public void AddAssembly(AssemblyInfo assemblyDefinition)
        {
            if (_assemblies.Any(vm => vm.AssemblyInfo == assemblyDefinition))
            {
                return;
            }

            _assemblies.Add(new AssemblyViewModel(assemblyDefinition, this));

            OnAssembliesChanged();
        }