コード例 #1
0
		public SimpleCompilation(ISolutionSnapshot solutionSnapshot, IUnresolvedAssembly mainAssembly, IEnumerable<IAssemblyReference> assemblyReferences)
		{
			if (solutionSnapshot == null)
				throw new ArgumentNullException("solutionSnapshot");
			if (mainAssembly == null)
				throw new ArgumentNullException("mainAssembly");
			if (assemblyReferences == null)
				throw new ArgumentNullException("assemblyReferences");
			this.solutionSnapshot = solutionSnapshot;
			this.context = new SimpleTypeResolveContext(this);
			this.mainAssembly = mainAssembly.Resolve(context);
			List<IAssembly> assemblies = new List<IAssembly>();
			assemblies.Add(this.mainAssembly);
			List<IAssembly> referencedAssemblies = new List<IAssembly>();
			foreach (var asmRef in assemblyReferences) {
				IAssembly asm;
				try {
					asm = asmRef.Resolve(context);
				} catch (InvalidOperationException) {
					throw new InvalidOperationException("Tried to initialize compilation with an invalid assembly reference. (Forgot to load the assembly reference ? - see CecilLoader)");
				}
				if (asm != null && !assemblies.Contains(asm))
					assemblies.Add(asm);
				if (asm != null && !referencedAssemblies.Contains(asm))
					referencedAssemblies.Add(asm);
			}
			this.assemblies = assemblies.AsReadOnly();
			this.referencedAssemblies = referencedAssemblies.AsReadOnly();
			this.knownTypeCache = new KnownTypeCache(this);
		}
コード例 #2
0
		public NSObjectProjectInfo GetProjectInfo (DotNetProject project, IAssembly lookinAssembly = null)
		{
			var dom = TypeSystemService.GetProjectContentWrapper (project);
			project.ReferenceAddedToProject += HandleDomReferencesUpdated;
			project.ReferenceRemovedFromProject += HandleDomReferencesUpdated;
			return GetProjectInfo (dom, lookinAssembly);
		}
コード例 #3
0
    /// <summary>
    /// Initializes a new instance of the <see cref="DerivedTypeInformation"/> class.
    /// </summary>
    /// <param name="assemblyManager">The assembly manager.</param>
    /// <param name="visibility">The visibility.</param>
    public DerivedTypeInformation(IAssemblyManager assemblyManager, IVisibilityConfiguration visibility)
    {
      this.table = new Dictionary<ITypeReference, List<ITypeDeclaration>>();

      IAssembly[] assemblies = new IAssembly[assemblyManager.Assemblies.Count];
      assemblyManager.Assemblies.CopyTo(assemblies, 0);

      FastTypeEnumerator enumerator = new FastTypeEnumerator(assemblies);
      foreach (ITypeDeclaration typeDeclaration in enumerator.Types)
      {
        if (ReflectorHelper.IsVisible(typeDeclaration, visibility))
        {
          ITypeReference baseType = typeDeclaration.BaseType;
          if (baseType != null)
          {
            if (baseType.GenericType != null)
            {
              this.AddToTable(baseType.GenericType, typeDeclaration);
            }
            else
            {
              this.AddToTable(baseType, typeDeclaration);
            }
          }

          foreach (ITypeReference interfaceType in typeDeclaration.Interfaces)
          {
            this.AddToTable(interfaceType, typeDeclaration);
          }
        }
      }
    }
コード例 #4
0
		private SimpleTypeResolveContext(ICompilation compilation, IAssembly currentAssembly, ITypeDefinition currentTypeDefinition, IMember currentMember)
		{
			this.compilation = compilation;
			this.currentAssembly = currentAssembly;
			this.currentTypeDefinition = currentTypeDefinition;
			this.currentMember = currentMember;
		}
		public override void ApplyTo(IAssembly assembly, IAttributeStore attributeStore, IErrorReporter errorReporter) {
			foreach (var t in assembly.GetAllTypeDefinitions()) {
				if (!attributeStore.AttributesFor(t).HasAttribute<DefaultMemberReflectabilityAttribute>()) {
					ApplyTo(t, attributeStore, errorReporter);
				}
			}
		}
コード例 #6
0
ファイル: BlobReader.cs プロジェクト: sphynx79/dotfiles
		public BlobReader(byte[] buffer, IAssembly currentResolvedAssembly)
		{
			if (buffer == null)
				throw new ArgumentNullException("buffer");
			this.buffer = buffer;
			this.currentResolvedAssembly = currentResolvedAssembly;
		}
コード例 #7
0
 public override List<ITestClass> GetTestClasses(IAssembly assembly, TestClassInstanceDictionary instances)
 {
     return new List<ITestClass>
     {
         _test
     };
 }
コード例 #8
0
ファイル: AssemblyResolver.cs プロジェクト: arkanoid1/dnSpy
		DnSpyFile ResolveNormal(IAssembly assembly, ModuleDef sourceModule, bool delayLoad) {
			var existingFile = fileList.FindAssembly(assembly);
			if (existingFile != null)
				return existingFile;

			var file = LookupFromSearchPaths(assembly, sourceModule, true);
			if (file != null)
				return fileList.AddFile(file, fileList.AssemblyLoadEnabled, delayLoad);

			if (fileList.UseGAC) {
				var gacFile = GacInterop.FindAssemblyInNetGac(assembly);
				if (gacFile != null)
					return fileList.GetOrCreate(gacFile, fileList.AssemblyLoadEnabled, true, delayLoad);
				foreach (var path in GacInfo.OtherGacPaths) {
					file = TryLoadFromDir(assembly, true, path);
					if (file != null)
						return fileList.AddFile(file, fileList.AssemblyLoadEnabled, delayLoad);
				}
			}

			file = LookupFromSearchPaths(assembly, sourceModule, false);
			if (file != null)
				return fileList.AddFile(file, fileList.AssemblyLoadEnabled, delayLoad);

			return null;
		}
コード例 #9
0
 /// <summary>
 /// Create a new assembly manager, takes in the harness, provider 
 /// reference and actual IAssembly object.
 /// </summary>
 /// <param name="runFilter">The test run filter object.</param>
 /// <param name="testHarness">Harness object.</param>
 /// <param name="provider">The unit test metadata provider.</param>
 /// <param name="testAssembly">The test assembly metadata object.</param>
 public AssemblyManager(TestRunFilter runFilter, UnitTestHarness testHarness, IUnitTestProvider provider, IAssembly testAssembly) : base(testHarness, provider)
 {
     _filter = runFilter;
     _assembly = testAssembly;
     _testClasses = new CompositeWorkItem();
     ClassInstances = new TestClassInstanceDictionary();
 }
コード例 #10
0
        private AsmReference GetReferences(IAssembly currentAssembly, AsmReference referenceDictionary, uint currentRecursionLimit = uint.MaxValue)
        {
            Contract.Requires<ArgumentNullException>(currentAssembly != null);
            Contract.Requires<ArgumentNullException>(referenceDictionary != null);

            if (referenceDictionary.ContainsKey(currentAssembly))
            {
                return referenceDictionary;
            }

            if (currentRecursionLimit == 0)
            {
                return referenceDictionary;
            }

            referenceDictionary.Add(currentAssembly, currentAssembly.References);
            currentRecursionLimit--;
            foreach (var referencedAssembly in currentAssembly.References)
            {
                var assemblyReferences = GetReferences(referencedAssembly, referenceDictionary, currentRecursionLimit);
                referenceDictionary.Add(assemblyReferences);
            }

            return referenceDictionary;
        }
コード例 #11
0
ファイル: WindowsService.cs プロジェクト: LionFree/Cush
        private WindowsService(bool interactive, IServiceWrapper wrapper, ILogger logger,
            ICommandLineParser parser, IConsoleHarness console, IAssembly assembly, 
            ServiceAttributeReader reader, WindowsServiceManager manager, HostFactory hostFactory)
        {
            Logger = logger;
            _metadata = reader.GetMetadata(this);

            _interactive = interactive;
            _assembly = assembly;
            Console = console;
            _manager = manager;
            _manager.SetMetadata(_metadata);
            _hostFactory = hostFactory;

            CommandLineParser = parser
                .SetApplicationName(reader.GetAttribute(this).DisplayName)
                .SetDescription(reader.GetAttribute(this).Description)
                .AddOption("quiet", "q", "Enable quiet mode. Will display only errors on the console.",
                    noArgs => _metadata.Quiet = true)
                .AddOption("silent", "si", "Enable silent mode. Will display nothing (not even errors) on the console.",
                    noArgs => _metadata.Silent = true)
                .AddOption("logtoconsole", "l", "Instructs the installer/uninstaller to log the output to the console.",
                    noArgs => _manager.LogToConsole = true)
                .AddOption("debug", "d", "Pauses to attach a debugger.", noArgs => EnableDebugMode())
                .AddOption("uninstall", "u", "Uninstalls the service.", noArgs => _manager.Uninstall())
                .AddOption("install", "i", "Installs the service.", noArgs => _manager.Install())
                .AddOption("installandstart", "is", "Installs and then starts the service.",
                    noArgs => _manager.InstallAndStart())
                .AddOption("start", "s", "Starts the service.", noArgs => _manager.StartService())
                .AddOption("stop", "x", "Stops the service.", noArgs => _manager.StopService())
                .AddOption("status", "st", "Displays the status of the service.", noArgs => _manager.ShowStatus());

            Harness = wrapper.WrapService(this);
        }
コード例 #12
0
 internal static WindowsServiceManager GetInstance(
     IConsoleHarness harness,
     IAssembly assembly,
     ManagedInstallerProxy installerProxy)
 {
     return new Implementation(harness, assembly, installerProxy);
 }
コード例 #13
0
ファイル: AssemblyDispatcher.cs プロジェクト: dfr0/moon
 public AssemblyDispatcher(UnitTestHarness testHarness, IUnitTestProvider provider, 
     IAssembly testAssembly) : base(testHarness, provider)
 {
     _assembly = testAssembly;
     _testClasses = new TestWorkItemDispatcher();
     _classInstances = new TestClassInstanceCollection();
 }
コード例 #14
0
 public ConstructorCallWeave(IAssembly parentAssembly, MethodDefinition parentMethod, Instruction newInstruction, MethodDefinition constructor)
 {
     _parentAssembly = parentAssembly;
       _parentMethod = parentMethod;
       _constructor = constructor;
       _newInstruction = newInstruction;
 }
コード例 #15
0
 public IProject GetProject(IAssembly assembly)
 {
     if (assembly != null)
         return GetProject(assembly.UnresolvedAssembly as IProjectContent);
     else
         return null;
 }
コード例 #16
0
		public IList<IAttribute> Resolve(IAssembly currentAssembly)
		{
			// TODO: make this a per-assembly cache
//				CacheManager cache = currentAssembly.Compilation.CacheManager;
//				IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this);
//				if (result != null)
//					return result;
			
			ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly);
			BlobReader reader = new BlobReader(blob, currentAssembly);
			if (reader.ReadByte() != '.') {
				// should not use UnresolvedSecurityDeclaration for XML secdecls
				throw new InvalidOperationException();
			}
			ResolveResult securityActionRR = securityAction.Resolve(context);
			uint attributeCount = reader.ReadCompressedUInt32();
			IAttribute[] attributes = new IAttribute[attributeCount];
			try {
				ReadSecurityBlob(reader, attributes, context, securityActionRR);
			} catch (NotSupportedException) {
				// ignore invalid blobs
				//Debug.WriteLine(ex.ToString());
			}
			for (int i = 0; i < attributes.Length; i++) {
				if (attributes[i] == null)
					attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType);
			}
			return attributes;
//				return (IList<IAttribute>)cache.GetOrAddShared(this, attributes);
		}
コード例 #17
0
        public void LocatesAllServiceRouteMappers()
        {
            var assemblyLocator = new Mock<IAssemblyLocator>();

            //including the assembly with object ensures that the assignabliity is done correctly
            var assembliesToReflect = new IAssembly[2];
            assembliesToReflect[0] = new AssemblyWrapper(GetType().Assembly);
            assembliesToReflect[1] = new AssemblyWrapper(typeof (Object).Assembly);

            assemblyLocator.Setup(x => x.Assemblies).Returns(assembliesToReflect);

            var locator = new TypeLocator {AssemblyLocator = assemblyLocator.Object};

            List<Type> types = locator.GetAllMatchingTypes(ServicesRoutingManager.IsValidServiceRouteMapper).ToList();

            //if new ServiceRouteMapper classes are added to the assembly they willl likely need to be added here
            CollectionAssert.AreEquivalent(
                new[]
                    {
                        typeof (FakeServiceRouteMapper),
                        typeof (ReflectedServiceRouteMappers.EmbeddedServiceRouteMapper),
                        typeof (ExceptionOnCreateInstanceServiceRouteMapper),
                        typeof (ExceptionOnRegisterServiceRouteMapper)
                    }, types);
        }
コード例 #18
0
		public SimpleCompilation(ISolutionSnapshot solutionSnapshot, IUnresolvedAssembly mainAssembly, IEnumerable<IAssemblyReference> assemblyReferences)
		{
			if (solutionSnapshot == null)
				throw new ArgumentNullException("solutionSnapshot");
			if (mainAssembly == null)
				throw new ArgumentNullException("mainAssembly");
			if (assemblyReferences == null)
				throw new ArgumentNullException("assemblyReferences");
			this.solutionSnapshot = solutionSnapshot;
			this.context = new SimpleTypeResolveContext(this);
			this.mainAssembly = mainAssembly.Resolve(context);
			List<IAssembly> assemblies = new List<IAssembly>();
			assemblies.Add(this.mainAssembly);
			List<IAssembly> referencedAssemblies = new List<IAssembly>();
			foreach (var asmRef in assemblyReferences) {
				IAssembly asm = asmRef.Resolve(context);
				if (asm != null && !assemblies.Contains(asm))
					assemblies.Add(asm);
				if (asm != null && !referencedAssemblies.Contains(asm))
					referencedAssemblies.Add(asm);
			}
			this.assemblies = assemblies.AsReadOnly();
			this.referencedAssemblies = referencedAssemblies.AsReadOnly();
			this.knownTypeCache = new KnownTypeCache(this);
		}
コード例 #19
0
ファイル: AssemblyVisitor.cs プロジェクト: halllo/MTSS12
 private void AnalyzeAssemblyInHost(IMetadataHost host, IAssembly assembly, string pdbPath)
 {
     if (pdbPath != null)
         AnalyzeAssemblyInHostWithProgramDatabase(assembly, host, pdbPath);
     else
         AnalyzeTypes(assembly, null, host, Report);
 }
コード例 #20
0
 public IEnumerable<ConstructorCallWeave> FindConstructorCallWeaves(IAssembly assembly, FactoryMap factories)
 {
     List<ConstructorCallWeave> spots = new List<ConstructorCallWeave>();
       foreach (TypeDefinition type in GetTypes(assembly, factories))
       {
     foreach (MethodDefinition method in type.Methods)
     {
       if (method.Body == null)
       {
     continue;
       }
       foreach (Instruction instruction in method.Body.Instructions)
       {
     if (instruction.OpCode == OpCodes.Newobj)
     {
       MethodDefinition constructor = instruction.Operand as MethodDefinition;
       if (constructor != null && constructor.Parameters.Count == 0)
       {
         if (factories.HasForObjectType(constructor.DeclaringType))
         {
           spots.Add(new ConstructorCallWeave(assembly, method, instruction, constructor));
         }
       }
     }
       }
     }
       }
       return spots;
 }
コード例 #21
0
		public SimpleTypeResolveContext(IAssembly assembly)
		{
			if (assembly == null)
				throw new ArgumentNullException("assembly");
			this.compilation = assembly.Compilation;
			this.currentAssembly = assembly;
		}
コード例 #22
0
        public BVE5Compilation(ISolutionSnapshot solutionSnapshot, IUnresolvedAssembly mainAssembly,
                               IEnumerable<IAssemblyReference> assemblyReferences)
        {
            if(solutionSnapshot == null)
                throw new ArgumentNullException("solutionSnapshot");

            if(mainAssembly == null)
                throw new ArgumentNullException("mainAssembly");

            if(assemblyReferences == null)
                throw new ArgumentNullException("assemblyReferences");

            solution_snapshot = solutionSnapshot;
            context = new SimpleTypeResolveContext(this);
            main_assembly = mainAssembly.Resolve(context);
            var assemblies = new List<IAssembly>{main_assembly};
            var referenced_assemblies = new List<IAssembly>();
            foreach(var asm_ref in assemblyReferences){
                IAssembly asm = asm_ref.Resolve(context);
                if(asm != null && !assemblies.Contains(asm))
                    assemblies.Add(asm);

                if(asm != null && !referenced_assemblies.Contains(asm))
                    referenced_assemblies.Add(asm);
            }

            this.assemblies = assemblies.AsReadOnly();
            this.referenced_assemblies = referenced_assemblies.AsReadOnly();
            this.type_cache = new PrimitiveTypeCache(this);
        }
コード例 #23
0
 public virtual List<ITestClass> GetTestClasses(IAssembly assembly, TestClassInstanceDictionary instances)
 {
     List<ITestClass> classes = new List<ITestClass>(assembly.GetTestClasses());
     FilterTestClasses(classes, instances);
     SortTestClasses(classes);
     return classes;
 }
コード例 #24
0
		internal static ITypeDefinition FindMyFormsClass(IAssembly asm, string myNamespace)
		{
			if (asm != null) {
				return asm.GetTypeDefinition(myNamespace, "MyForms", 0);
			}
			return null;
		}
コード例 #25
0
 public override void TraverseChildren(IAssembly assembly) {
   foreach (IModule module in assembly.MemberModules) {
     assemblyBeingTranslated = module.ContainingAssembly;
     this.Traverse(module);
   }
   firstPassDone = true;
 }
コード例 #26
0
		public NSObjectProjectInfo (TypeSystemService.ProjectContentWrapper dom, NSObjectInfoService infoService, IAssembly lookinAssembly)
		{
			this.infoService = infoService;
			this.dom = dom;
			this.lookinAssembly = lookinAssembly;
			needsUpdating = true;
		}
コード例 #27
0
 public override void Visit(IAssembly assembly)
 {
     this.module = assembly;
     this.Visit((IModule)assembly);
     this.Visit(assembly.GetFiles(Context));
     this.Visit(assembly.GetResources(Context));
 }
コード例 #28
0
		private string Process(IList<JsStatement> stmts, IAssembly mainAssembly, IMetadataImporter metadata = null, INamer namer = null) {
			var compilation = new Mock<ICompilation>();
			compilation.SetupGet(_ => _.MainAssembly).Returns(mainAssembly);
			var obj = new Linker(metadata ?? new MockMetadataImporter(), namer ?? new MockNamer(), compilation.Object);
			var processed = obj.Process(stmts);
			return string.Join("", processed.Select(s => OutputFormatter.Format(s, allowIntermediates: false)));
		}
コード例 #29
0
        public static void extract_all_resources_to_relative_directory(IFileSystem fileSystem, IAssembly assembly, string directoryPath, IList<string> relativeDirectories, string resourcesToInclude, bool overwriteExisting = false, bool logOutput = false)
        {
            var resourceString = new StringBuilder();
            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                if (!resourceName.StartsWith(resourcesToInclude))
                {
                    continue;
                }
                resourceString.Clear();
                resourceString.Append(resourceName);

                //var fileExtensionLocation = resourceName.LastIndexOf('.');
                //resourceString.Remove(fileExtensionLocation, resourceString.Length - fileExtensionLocation);
                resourceString.Replace(resourcesToInclude + ".", "");
                foreach (var directory in relativeDirectories)
                {
                    resourceString.Replace("{0}".format_with(directory), "{0}{1}".format_with(directory, fileSystem.get_path_directory_separator_char()));
                }

                // replacing \. with \
                resourceString.Replace("{0}.".format_with(fileSystem.get_path_directory_separator_char()), "{0}".format_with(fileSystem.get_path_directory_separator_char()));

                var fileLocation = resourceString.ToString();
                //var fileLocation = fileSystem.combine_paths("", resourceString.ToString().Split('.')) + resourceName.Substring(fileExtensionLocation);

                var filePath = fileSystem.combine_paths(directoryPath, fileLocation);
                if (logOutput) "chocolatey".Log().Debug("Unpacking {0} to '{1}'".format_with(fileLocation,filePath));
                extract_binary_file_from_assembly(fileSystem, assembly, resourceName, filePath, overwriteExisting);
            }
        }
コード例 #30
0
 /// <summary>
 ///   Extract binary file from an assembly to a location on disk
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="assembly">The assembly.</param>
 /// <param name="manifestLocation">The manifest location.</param>
 /// <param name="filePath">The file path.</param>
 /// <param name="overwriteExisting">
 ///   if set to <c>true</c> [overwrite existing].
 /// </param>
 public static void extract_binary_file_from_assembly(IFileSystem fileSystem, IAssembly assembly, string manifestLocation, string filePath, bool overwriteExisting = false)
 {
     if (overwriteExisting || !fileSystem.file_exists(filePath))
     {
         fileSystem.create_directory_if_not_exists(fileSystem.get_directory_name(filePath));
         fileSystem.write_file(filePath, () => assembly.get_manifest_stream(manifestLocation));
     }
 }