当前位置: 首页>>代码示例>>C#>>正文


C# ResolveEventHandler类代码示例

本文整理汇总了C#中ResolveEventHandler的典型用法代码示例。如果您正苦于以下问题:C# ResolveEventHandler类的具体用法?C# ResolveEventHandler怎么用?C# ResolveEventHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResolveEventHandler类属于命名空间,在下文中一共展示了ResolveEventHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        //===================================================================
        // Initialization performed on startup of the Python runtime. Here we
        // scan all of the currently loaded assemblies to determine exported
        // names, and register to be notified of new assembly loads.
        //===================================================================

        internal static void Initialize()
        {
            namespaces = new
                Dictionary<string, Dictionary<Assembly, string>>(32);
            probed = new Dictionary<string, int>(32);
            //generics = new Dictionary<string, Dictionary<string, string>>();
            assemblies = new List<Assembly>(16);
            pypath = new List<string>(16);

            AppDomain domain = AppDomain.CurrentDomain;

            lhandler = new AssemblyLoadEventHandler(AssemblyLoadHandler);
            domain.AssemblyLoad += lhandler;

            rhandler = new ResolveEventHandler(ResolveHandler);
            domain.AssemblyResolve += rhandler;

            Assembly[] items = domain.GetAssemblies();
            foreach (var a in items)
            {
                try
                {
                    ScanAssembly(a);
                    assemblies.Add(a);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error scanning assembly {0}. {1}", a, ex));
                }
            }
        }
开发者ID:denfromufa,项目名称:pythonnet,代码行数:37,代码来源:assemblymanager.cs

示例2: InstallHandler

        /// <summary>
        /// Installs an AssemblyResolve handler in the current AppDomain. This class can be created in any AppDomain, 
        /// so it's possible to create an AppDomain, create an instance of this class in it and use this method to install
        /// an event handler in that AppDomain. Since the event handler instance is stored internally, this method
        /// should only be called once before a corresponding call to RemoveHandler (not that it would make sense to do 
        /// anything else).
        /// </summary>
        /// <owner>lukaszg</owner>
        internal void InstallHandler()
        {
            Debug.Assert(eventHandler == null, "The TaskEngineAssemblyResolver.InstallHandler method should only be called once!");

            eventHandler = new ResolveEventHandler(ResolveAssembly);
            AppDomain.CurrentDomain.AssemblyResolve += eventHandler;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:15,代码来源:TaskEngineAssemblyResolver.cs

示例3: Sandbox

        //Create a SandBox to load Assemblies with "Full Trust"
        public static ServiceBridge Sandbox(string assemblyFilename, string configPath, ResolveEventHandler handler)
        {
            var trustedLoadGrantSet = new PermissionSet(PermissionState.Unrestricted);
            var trustedLoadSetup = new AppDomainSetup();
            trustedLoadSetup.ApplicationBase = Path.GetDirectoryName(assemblyFilename);
            trustedLoadSetup.PrivateBinPath = Path.GetDirectoryName(assemblyFilename);
            //trustedLoadSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            trustedLoadSetup.ConfigurationFile = configPath;

            AppDomain.CurrentDomain.AssemblyResolve += handler;
            AppDomain appDomain = AppDomain.CreateDomain("ServiceBridge SandBox", null, trustedLoadSetup, trustedLoadGrantSet);
            appDomain.SetData("DataDirectory", configPath.Replace("Web.config", "App_Data"));

            ServiceBridge loader = appDomain.CreateInstanceAndUnwrap(
                typeof(ServiceBridge).Assembly.GetName().FullName,
                typeof(ServiceBridge).FullName,
                false,
                BindingFlags.Default,
                null,
                new object[] { assemblyFilename },
                CultureInfo.InvariantCulture,
                null) as ServiceBridge;

            return loader;
        }
开发者ID:umbraco,项目名称:Visual-Studio-Extension,代码行数:26,代码来源:ServiceBridge.cs

示例4: BuildAndLoad

        public static Assembly BuildAndLoad(string[] sourcePaths, string[] referencePaths, string[] defines)
        {
            var assemblyName = Path.GetRandomFileName();
            var parseOption = new CSharpParseOptions(LanguageVersion.CSharp6, DocumentationMode.Parse, SourceCodeKind.Regular, defines);
            var syntaxTrees = sourcePaths.Select(file => CSharpSyntaxTree.ParseText(File.ReadAllText(file), parseOption, file)).ToArray();
            var references = referencePaths.Select(file => MetadataReference.CreateFromFile(file)).ToArray();
            var referenceMaps = referencePaths.Select(file => Assembly.LoadFile(file))
                                              .ToDictionary(a => a.FullName, a => a);

            var compilation = CSharpCompilation.Create(
                assemblyName,
                syntaxTrees: syntaxTrees,
                references: references,
                options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

            using (var ms = new MemoryStream())
            {
                var result = compilation.Emit(ms);

                if (!result.Success)
                {
                    var failures = result.Diagnostics.Where(diagnostic =>
                        diagnostic.IsWarningAsError ||
                        diagnostic.Severity == DiagnosticSeverity.Error);

                    foreach (var diagnostic in failures)
                    {
                        var line = diagnostic.Location.GetLineSpan();
                        Console.Error.WriteLine("{0}({1}): {2} {3}",
                            line.Path,
                            line.StartLinePosition.Line + 1,
                            diagnostic.Id,
                            diagnostic.GetMessage());
                    }
                    return null;
                }
                else
                {
                    ms.Seek(0, SeekOrigin.Begin);

                    // To load referenced assemblies, set customized resolved during using this assembly.

                    var currentDomain = AppDomain.CurrentDomain;
                    var resolveHandler = new ResolveEventHandler((sender, args) =>
                    {
                        Assembly assembly;
                        return referenceMaps.TryGetValue(args.Name, out assembly) ? assembly : null;
                    });

                    if (_lastResolveHandler != null)
                        currentDomain.AssemblyResolve -= _lastResolveHandler;
                    currentDomain.AssemblyResolve += resolveHandler;
                    _lastResolveHandler = resolveHandler;

                    return Assembly.Load(ms.ToArray());
                }
            }
        }
开发者ID:SaladLab,项目名称:Akka.Interfaced,代码行数:58,代码来源:AssemblyLoader.cs

示例5: Init

 internal void Init(TempAssembly tempAssembly)
 {
     this.tempAssembly = tempAssembly;
     if ((tempAssembly != null) && tempAssembly.NeedAssembyResolve)
     {
         this.threadCode = Thread.CurrentThread.GetHashCode();
         this.assemblyResolver = new ResolveEventHandler(this.OnAssemblyResolve);
         AppDomain.CurrentDomain.AssemblyResolve += this.assemblyResolver;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:XmlSerializationGeneratedCode.cs

示例6: Init

 internal void Init(TempAssembly tempAssembly) {
     this.tempAssembly = tempAssembly;
     // only hook the assembly resolver if we have something to help us do the resolution
     if (tempAssembly != null && tempAssembly.NeedAssembyResolve) {
         // we save the threadcode to make sure we don't handle any resolve events for any other threads
         threadCode = Thread.CurrentThread.GetHashCode();
         assemblyResolver = new ResolveEventHandler(OnAssemblyResolve);
         AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver;
     }
 }
开发者ID:uQr,项目名称:referencesource,代码行数:10,代码来源:XmlSerializationGeneratedCode.cs

示例7: Test_SetAssemblyEvent_01

 public static void Test_SetAssemblyEvent_01()
 {
     Test_UnsetAssemblyEvent_01();
     _tr.WriteLine("Test_SetAssemblyEvent_01");
     ResolveEventHandler resolveEventHandler = new ResolveEventHandler(CurrentDomain_AssemblyResolve);
     AssemblyLoadEventHandler assemblyLoadEventHandler = new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
     _rs.Data.Add("ResolveEventHandler", resolveEventHandler);
     _rs.Data.Add("AssemblyLoadEventHandler", assemblyLoadEventHandler);
     AppDomain.CurrentDomain.AssemblyResolve += resolveEventHandler;
     AppDomain.CurrentDomain.AssemblyLoad += assemblyLoadEventHandler;
 }
开发者ID:labeuze,项目名称:source,代码行数:11,代码来源:Test_JScript_f.cs

示例8: Add

		public void Add(ProjectItem item, EventModel model, IEnumerable<IEventScript> scripts, ResolveEventHandler resolver)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			var entry = new Entry(item, model, scripts, resolver);

			var project = item.ContainingProject;
	
			Dictionary<ProjectItem, Entry> items;
			if (!_entries.TryGetValue(project, out items))
			{
				// Add project entry
				items = new Dictionary<ProjectItem, Entry>();
				_entries.Add(project, items);
			}

			items.Add(item, entry);
		}
开发者ID:MartinF,项目名称:Dynamo.Jiss,代码行数:19,代码来源:Index.cs

示例9: Sandbox

        /// <summary>
        /// The sandbox.
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <param name="assemblyFilenames">
        /// The assembly filenames.
        /// </param>
        /// <param name="handler">
        /// The handler.
        /// </param>
        /// <returns>
        /// The <see cref="PluginSandBoxLoader"/>.
        /// </returns>
        public static PluginSandBoxLoader Sandbox(
            AppDomain domain,
            string[] assemblyFilenames,
            ResolveEventHandler handler)
        {
            //AppDomain.CurrentDomain.AssemblyResolve += handler;

            var loader =
                domain.CreateInstanceAndUnwrap(
                    typeof(PluginSandBoxLoader).Assembly.GetName().FullName,
                    typeof(PluginSandBoxLoader).FullName,
                    false,
                    BindingFlags.Default,
                    null,
                    new object[] { assemblyFilenames },
                    CultureInfo.InvariantCulture,
                    null) as PluginSandBoxLoader;

            return loader;
        }
开发者ID:kanchanachalla,项目名称:VSSonarQubeExtension,代码行数:35,代码来源:PluginSandBoxLoader.cs

示例10: Initialize

	//===================================================================
	// Initialization performed on startup of the Python runtime.
	//===================================================================

	internal static void Initialize() {
	    pypath = new StringCollection();
	    namespaces = new Hashtable();
	    assemblies = new ArrayList();
	    probed = new Hashtable();

	    AppDomain domain = AppDomain.CurrentDomain;

	    lh = new AssemblyLoadEventHandler(AssemblyLoadHandler);
	    domain.AssemblyLoad += lh;

	    rh = new ResolveEventHandler(ResolveHandler);	
	    domain.AssemblyResolve += rh;

	    Assembly[] items = domain.GetAssemblies();
	    for (int i = 0; i < items.Length; i++) {
		Assembly a = items[i];
		assemblies.Add(a);
		ScanAssembly(a);
	    }
	}
开发者ID:fkarb,项目名称:pythonnet,代码行数:25,代码来源:assemblymanager.cs

示例11: SetupAssemblyResolve

        void SetupAssemblyResolve(ResolveEventHandler resolveEventHandler)
        {
            if (resolveEventHandler == null)
            {
                _resolveEventHandler = new ResolveEventHandler(DefaultResolveEventHandler);
            }
            else
            {
                _resolveEventHandler = resolveEventHandler;
            }
            _resolveDirs = new List<string>();
            AppDomain.CurrentDomain.AssemblyResolve += _resolveEventHandler;


            string reflector = Config.Reflector;
            if (!String.IsNullOrEmpty(reflector) && File.Exists(reflector))
            {
                AddAssemblyResolveDir(Path.GetDirectoryName(reflector));
            }
            
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:21,代码来源:CoreAssemblyResolver.cs

示例12: Entry

		public Entry(ProjectItem item, EventModel model, IEnumerable<IEventScript> scripts, ResolveEventHandler resolver)
		{
			if (item == null)
				throw new ArgumentNullException("item");
			if (model == null)
				throw new ArgumentNullException("model");
			if (scripts == null)
				throw new ArgumentNullException("scripts");
			if (resolver == null)
				throw new ArgumentNullException("resolver");

			if (!scripts.Any())
				throw new ArgumentException("Scripts should not be 0.", "scripts");

			ProjectItem = item;
			EventModel = model;

			//Assembly = scripts.First().GetType().Assembly;						// Dont require the Assembly to be passed ?
			
			_scripts.AddRange(scripts);	
			Resolver = resolver;
		}
开发者ID:MartinF,项目名称:Dynamo.Jiss,代码行数:22,代码来源:Entry.cs

示例13: Initialize

        //===================================================================
        // Initialization performed on startup of the Python runtime. Here we
        // scan all of the currently loaded assemblies to determine exported
        // names, and register to be notified of new assembly loads.
        //===================================================================

        internal static void Initialize() {
            namespaces = new 
                         Dictionary<string, Dictionary<Assembly, string>>(32);
            probed = new Dictionary<string, int>(32);
            //generics = new Dictionary<string, Dictionary<string, string>>();
            assemblies = new List<Assembly>(16);
            pypath = new List<string>(16);

            AppDomain domain = AppDomain.CurrentDomain;

            lhandler = new AssemblyLoadEventHandler(AssemblyLoadHandler);
            domain.AssemblyLoad += lhandler;

            rhandler = new ResolveEventHandler(ResolveHandler);        
            domain.AssemblyResolve += rhandler;

            Assembly[] items = domain.GetAssemblies();
            for (int i = 0; i < items.Length; i++) {
                Assembly a = items[i];
                assemblies.Add(a);
                ScanAssembly(a);
            }
        }
开发者ID:ruisebastiao,项目名称:pythonnet,代码行数:29,代码来源:assemblymanager.cs

示例14: add_assembly_resolver

        private static void add_assembly_resolver()
        {
            _handler = (sender, args) =>
            {
                var requestedAssembly = new AssemblyName(args.Name);
                if (requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
                    && !requestedAssembly.Name.is_equal_to("chocolatey.licensed")
                    && !requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
                {
                    return typeof(ConsoleApplication).Assembly;
                }

                try
                {
                    if (requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
                        && requestedAssembly.Name.is_equal_to("chocolatey.licensed"))
                    {
                        return Assembly.LoadFile(ApplicationParameters.LicensedAssemblyLocation).UnderlyingType;
                    }
                }
                catch (Exception ex)
                {
                    "chocolatey".Log().Warn("Unable to load chocolatey.licensed assembly. {0}".format_with(ex.Message));
                }

                return null;
            };

            AppDomain.CurrentDomain.AssemblyResolve += _handler;
        }
开发者ID:RichiCoder1,项目名称:choco,代码行数:30,代码来源:Program.cs

示例15: Dispose

 public void Dispose()
 {
     if (_assemblyResolver != null) {
         AppDomain.CurrentDomain.AssemblyResolve -= _assemblyResolver;
         _assemblyResolver = null;
     }
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:ActivationWorker.cs


注:本文中的ResolveEventHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。