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


C# AppDomain.CreateInstanceFrom方法代码示例

本文整理汇总了C#中System.AppDomain.CreateInstanceFrom方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.CreateInstanceFrom方法的具体用法?C# AppDomain.CreateInstanceFrom怎么用?C# AppDomain.CreateInstanceFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.AppDomain的用法示例。


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

示例1: DomainContainer

 public DomainContainer(string clientDllPath, string version, int databasePort)
 {
     var clientDllFolder = System.IO.Path.GetDirectoryName(clientDllPath);
     var testSuiteRunningFolder = AppDomain.CurrentDomain.BaseDirectory;
     var setup = new AppDomainSetup();
     setup.ApplicationBase = clientDllFolder;
     domain = AppDomain.CreateDomain(version, null, setup);
     Type loaderType = typeof(Wrapper);
     wrapperProxy = (Wrapper)domain.CreateInstanceFrom(loaderType.Assembly.Location, loaderType.FullName).Unwrap();
     wrapperProxy.LoadAssemblyAndSetUp(clientDllPath, testSuiteRunningFolder, databasePort);
 }
开发者ID:ppekrol,项目名称:raven.testsuite,代码行数:11,代码来源:DomainContainer.cs

示例2: RegisterAssembplyImport

        /// <summary>
        /// Registers the assembply import.
        /// </summary>
        /// <param name="hostAppDomain">The host application domain.</param>
        public static void RegisterAssembplyImport(AppDomain hostAppDomain)
        {
            var assemblyImportType = typeof(AssemblyImport);

            hostAppDomain.CreateInstanceFrom(assemblyImportType.Assembly.CodeBase,
                    assemblyImportType.FullName,
                    true,
                    BindingFlags.CreateInstance,
                    null,
                    new object[] { AppDomain.CurrentDomain.BaseDirectory },
                    null,
                    new object[0]);
        }
开发者ID:weitaoxiao,项目名称:NDock,代码行数:17,代码来源:AssemblyImport.cs

示例3: LoadAssembly

		/// <span class="code-SummaryComment"><summary></span>
		/// Loads an assembly into a new AppDomain and obtains all the
		/// namespaces in the loaded Assembly, which are returned as a 
		/// List. The new AppDomain is then Unloaded
		/// <span class="code-SummaryComment"></summary></span>
		/// <span class="code-SummaryComment"><param name="assemblyLocation">The Assembly file </span>
		/// location<span class="code-SummaryComment"></param></span>
		/// <span class="code-SummaryComment"><returns>A list of found namespaces</returns></span>
		public LoadResult LoadAssembly(FileInfo assemblyLocation)
		{
			LoadResult rlt = new LoadResult();
			List<String> namespaces = new List<String>();

			if (string.IsNullOrEmpty(assemblyLocation.Directory.FullName))
			{
				throw new InvalidOperationException(
					"Directory can't be null or empty.");
			}

			if (!Directory.Exists(assemblyLocation.Directory.FullName))
			{
				throw new InvalidOperationException(
				   string.Format(CultureInfo.CurrentCulture,
				   "Directory not found {0}",
				   assemblyLocation.Directory.FullName));

			}

			childDomain = BuildChildDomain(
				AppDomain.CurrentDomain);

			try
			{
				Type loaderType = typeof (AssemblyLoader);
				if (loaderType.Assembly != null)
				{
					var loader =
						(AssemblyLoader) childDomain.
							CreateInstanceFrom(
								loaderType.Assembly.Location,
								loaderType.FullName).Unwrap();

					rlt.Assembly = loader.LoadAssembly(
						assemblyLocation.FullName);
					namespaces =
						loader.GetNamespaces(
							assemblyLocation.Directory.FullName);
				}
			}
			catch (Exception ex)
			{
				if (Debugger.IsAttached)
				{
					Debugger.Break();
				}
			}
			rlt.Namespaces = namespaces != null ? namespaces.ToArray() : null;
			return rlt;
		}
开发者ID:mind0n,项目名称:hive,代码行数:59,代码来源:DomainLoader.cs

示例4: BuildPluginProject

        /// <summary>
        /// Creates an instance of the specified mojo name within the specified application domain.
        /// </summary>
        /// <param name="mojoName">the name of the mojo to create</param>
        /// <param name="pluginAssemblyFile">the.NET maven plugin</param>
        /// <param name="paramFile">the file containing the parameters to inject into an instance 
        /// of the specified mojo</param>
        /// <param name="applicationDomain">
        /// the application domain used to create the specified mojo name instance</param>
        /// <returns>an instance of the specified mojo name within the specified application domain</returns>
        internal int BuildPluginProject(AppDomain applicationDomain, FileInfo pluginArtifact,
                                        FileInfo outputDirectory, string groupId, string artifactId,
                                        string version)
        {
            ObjectHandle objectHandle =
                applicationDomain.CreateInstanceFrom(@pluginArtifact.FullName,
                                                     "NPanday.Plugin.Generator.JavaClassUnmarshaller");
            JavaClassUnmarshaller jcuRemote = (JavaClassUnmarshaller)objectHandle.Unwrap();
            List<JavaClass> javaClasses = jcuRemote.GetMojosFor(artifactId, groupId);
            JavaClassUnmarshaller jcuLocal = new JavaClassUnmarshaller();

            char[] delim = { '.' };
            DirectoryInfo sourceDirectory = new DirectoryInfo(@outputDirectory.FullName + "/src/main/java/"
                                                              + artifactId.Replace('.', '/'));
            sourceDirectory.Create();
            if (javaClasses.Count == 0)
            {
                Console.WriteLine("NPanday-000-000: There are no Mojos within the assembly: Artifact Id = "
                                  + artifactId);
                return 1;
            }

            foreach (JavaClass javaClass in javaClasses)
            {
                string[] tokens = javaClass.ClassName.Split(delim);
                string classFileName = tokens[tokens.Length - 1];
                FileInfo fileInfo = new FileInfo(sourceDirectory.FullName + "/"
                                                 + classFileName + ".java");
                jcuLocal.unmarshall(javaClass, fileInfo);
            }

            TextReader reader = new StreamReader(typeof(Generator).Assembly
                .GetManifestResourceStream("NPanday.Plugin.MojoGenerator.pom-java.xml"));

            XmlSerializer serializer = new XmlSerializer(typeof(NPanday.Model.Pom.Model));
            NPanday.Model.Pom.Model model = (NPanday.Model.Pom.Model)serializer.Deserialize(reader);
            model.artifactId = artifactId + ".JavaBinding";
            model.groupId = groupId;
            model.version = version;
            model.name = artifactId + ".JavaBinding";

            FileInfo outputPomXml = new FileInfo(@outputDirectory.FullName + "/pom-java.xml");
            TextWriter textWriter = new StreamWriter(@outputPomXml.FullName);
            serializer.Serialize(textWriter, model);

            return 0;
        }
开发者ID:tocsleung,项目名称:npanday,代码行数:57,代码来源:Generator.cs

示例5: CreateRemoteEnumeratorInAppdomain

        private RemoteEnumerator CreateRemoteEnumeratorInAppdomain(AppDomain testDomain)
        {
            RemoteEnumerator remoteEnum;
            Type remoteEnumType = typeof(RemoteEnumerator);

            remoteEnum = (RemoteEnumerator)testDomain.CreateInstanceFrom(
                                               remoteEnumType.Assembly.Location, remoteEnumType.FullName).Unwrap();
            return remoteEnum;
        }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:9,代码来源:DirectoryLookupModuleEnumeratorFixture.cs

示例6: CreateInstance

        /// <summary>
        /// Factory method used to create a DomainInitializer in an AppDomain.
        /// </summary>
        /// <param name="targetDomain">The domain in which to create the agent</param>
        /// <param name="traceLevel">The level of internal tracing to use</param>
        /// <returns>A proxy for the DomainAgent in the other domain</returns>
        public static DomainInitializer CreateInstance(AppDomain targetDomain)
        {
            #if NET_2_0
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstanceFrom(
                targetDomain,
            #else
            System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstanceFrom(
            #endif
                typeof(DomainInitializer).Assembly.CodeBase,
                typeof(DomainInitializer).FullName,
                false, BindingFlags.Default, null, null, null, null, null);

            object obj = oh.Unwrap();
            Type type = obj.GetType();
            return (DomainInitializer)obj;
        }
开发者ID:caleb-vear,项目名称:shouldly,代码行数:22,代码来源:DomainAgent.cs

示例7: CreateRunner

        /// <summary>
        /// Runs a single testcase.
        /// </summary>
        /// <param name="assemblyFile">The test assembly.</param>
        /// <param name="configFile">The application configuration file for the test domain.</param>
        /// <param name="referenceAssemblies">List of files to scan for missing assembly references.</param>
        /// <returns>
        /// The result of the test.
        /// </returns>
        public TestRunner CreateRunner(FileInfo assemblyFile, FileInfo configFile, StringCollection referenceAssemblies)
        {
            // create test domain
            _domain = CreateDomain(assemblyFile.Directory, assemblyFile,
                configFile);

            // assemble directories which can be probed for missing unresolved
            // assembly references
            string[] probePaths = null;

            if (AppDomain.CurrentDomain.SetupInformation.PrivateBinPath != null) {
                string [] privateBinPaths = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath.Split(Path.PathSeparator);
                probePaths = new string [privateBinPaths.Length + 1];
                for (int i = 0; i < privateBinPaths.Length; i++) {
                    probePaths[i] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                        privateBinPaths[i]);
                }
            } else {
                probePaths = new string[1];
            }

            string[] references = new string[referenceAssemblies.Count];
            referenceAssemblies.CopyTo (references, 0);

            // add base directory of current AppDomain as probe path
            probePaths [probePaths.Length - 1] = AppDomain.CurrentDomain.BaseDirectory;

            // create an instance of our custom Assembly Resolver in the target domain.
            #if NET_4_0
            _domain.CreateInstanceFrom(Assembly.GetExecutingAssembly().CodeBase,
                    typeof(AssemblyResolveHandler).FullName,
                    false,
                    BindingFlags.Public | BindingFlags.Instance,
                    null,
                    new object[] {probePaths, references},
                    CultureInfo.InvariantCulture,
                    null);
            #else
            _domain.CreateInstanceFrom(Assembly.GetExecutingAssembly().CodeBase,
                    typeof(AssemblyResolveHandler).FullName,
                    false,
                    BindingFlags.Public | BindingFlags.Instance,
                    null,
                    new object[] {probePaths, references},
                    CultureInfo.InvariantCulture,
                    null,
                    AppDomain.CurrentDomain.Evidence);
            #endif
            // create testrunner
            return CreateTestRunner(_domain);
        }
开发者ID:radleta,项目名称:nant,代码行数:60,代码来源:NUnit2TestDomain.cs

示例8: GetHandler

        private IStoryHandler GetHandler()
        {
            // Construct and initialize settings for a second AppDomain.
            var domainSetup = new AppDomainSetup();
            if (InTest)
            {
                domainSetup.ApplicationBase = Environment.CurrentDirectory;
                domainSetup.DisallowBindingRedirects = false;
            }
            else
            {
                domainSetup.ApplicationBase = Path.GetDirectoryName(_assemblyLocations.First());
                domainSetup.DisallowBindingRedirects = false;
            }
            domainSetup.ShadowCopyFiles = "true";
            domainSetup.ShadowCopyDirectories = GetDirectories(_assemblyLocations);
            domainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            // Create the second AppDomain.
            _appDomain = AppDomain.CreateDomain("TestDomain", null, domainSetup);

            return _appDomain.CreateInstanceFrom(
                _assemblyLocation,
                "StorEvilTestAssembly.StorEvilDriver", true, 0, null, new object[] {_eventBus},
                CultureInfo.CurrentCulture, new object[0], AppDomain.CurrentDomain.Evidence).Unwrap() as IStoryHandler;
        }
开发者ID:pawelpabich,项目名称:storevil,代码行数:26,代码来源:RemoteStoryHandler.cs

示例9: Start

        /// <summary>
        /// Starts this server instance.
        /// </summary>
        /// <returns>
        /// return true if start successfull, else false
        /// </returns>
        public bool Start()
        {
            try
            {
                var currentDomain = AppDomain.CurrentDomain;
                var marshalServerType = typeof(MarshalAppServer);

                var workingDir = Path.Combine(Path.Combine(currentDomain.BaseDirectory, m_WorkingDir), Name);

                if (!Directory.Exists(workingDir))
                    Directory.CreateDirectory(workingDir);

                var startupConfigFile = m_Bootstrap.StartupConfigFile;

                if (!string.IsNullOrEmpty(startupConfigFile))
                {
                    if (!Path.IsPathRooted(startupConfigFile))
                        startupConfigFile = Path.Combine(currentDomain.BaseDirectory, startupConfigFile);
                }

                m_HostDomain = AppDomain.CreateDomain(m_ServerConfig.Name, currentDomain.Evidence, new AppDomainSetup
                    {
                        ApplicationName = m_ServerConfig.Name,
                        ApplicationBase = workingDir,
                        ConfigurationFile = startupConfigFile
                    });

                var assemblyImportType = typeof(AssemblyImport);

                m_HostDomain.CreateInstanceFrom(assemblyImportType.Assembly.CodeBase,
                        assemblyImportType.FullName,
                        true,
                        BindingFlags.CreateInstance,
                        null,
                        new object[] { currentDomain.BaseDirectory },
                        null,
                        new object[0]);

                m_AppServer = (IWorkItem)m_HostDomain.CreateInstanceAndUnwrap(marshalServerType.Assembly.FullName,
                        marshalServerType.FullName,
                        true,
                        BindingFlags.CreateInstance,
                        null,
                        new object[] { m_ServiceTypeName },
                        null,
                        new object[0]);

                if (!m_AppServer.Setup(m_Bootstrap, m_ServerConfig, m_Factories))
                    throw new Exception("Failed tp setup MarshalAppServer");
            }
            catch (Exception)
            {
                if (m_HostDomain != null)
                {
                    AppDomain.Unload(m_HostDomain);
                    m_HostDomain = null;
                }

                if (m_AppServer != null)
                {
                    m_AppServer = null;
                }

                return false;
            }

            return m_AppServer.Start();
        }
开发者ID:kinghuc,项目名称:521266750_qq_com,代码行数:74,代码来源:AppDomainAppServer.cs

示例10: CreateAbstractMojoFor

        /// <summary>
        /// Creates an instance of the specified mojo name within the specified application domain.
        /// </summary>
        /// <param name="mojoName">the name of the mojo to create</param>
        /// <param name="pluginAssemblyFile">the.NET maven plugin</param>
        /// <param name="paramFile">the file containing the parameters to inject into an instance 
        /// of the specified mojo</param>
        /// <param name="applicationDomain">
        /// the application domain used to create the specified mojo name instance</param>
        /// <returns>an instance of the specified mojo name within the specified application domain</returns>
        internal AbstractMojo CreateAbstractMojoFor(String mojoName, FileInfo pluginAssemblyFile, 
		                                          FileInfo paramFile, AppDomain applicationDomain)
        {
            ObjectHandle objectHandle =
                applicationDomain.CreateInstanceFrom(pluginAssemblyFile.FullName, mojoName);
            AbstractMojo abstractMojo = (AbstractMojo) objectHandle.Unwrap();
            abstractMojo.InjectFields(paramFile.FullName);
            return abstractMojo;
        }
开发者ID:tocsleung,项目名称:npanday,代码行数:19,代码来源:PluginLoader.cs

示例11: CreateInstance

 /// <summary>
 /// Create an instance of the required type using the AppDomain
 /// </summary>
 /// <param name="compileAppDomain"></param>
 /// <param name="assemblyLocation"></param>
 /// <param name="classType"></param>
 /// <param name="assemblyCodeBase"></param>
 /// <returns></returns>
 private static object CreateInstance(AppDomain compileAppDomain, string assemblyLocation,
     Type classType, string assemblyCodeBase)
 {
     object instance = null;
     try
     {
         instance = compileAppDomain.CreateInstanceFrom(assemblyLocation, classType.FullName).Unwrap();
     }
     catch (Exception)
     {
     }
     if (instance == null)
     {
         try
         {
             instance = compileAppDomain.CreateInstanceFrom(assemblyCodeBase, classType.FullName).Unwrap();
         }
         catch (Exception)
         {
         }
     }
     return instance;
 }
开发者ID:kendarorg,项目名称:SharpTemplateEngine,代码行数:31,代码来源:SourceCompiler.cs

示例12: CreateRemoteDirectoryModuleCatalogInAppDomain

        private RemoteDirectoryLookupCatalog CreateRemoteDirectoryModuleCatalogInAppDomain(AppDomain testDomain)
        {
            RemoteDirectoryLookupCatalog remoteEnum;
            Type remoteEnumType = typeof(RemoteDirectoryLookupCatalog);

            remoteEnum = (RemoteDirectoryLookupCatalog)testDomain.CreateInstanceFrom(
                                               remoteEnumType.Assembly.Location, remoteEnumType.FullName).Unwrap();
            return remoteEnum;
        }
开发者ID:CarlosVV,项目名称:mediavf,代码行数:9,代码来源:DirectoryModuleCatalogFixture.Desktop.cs

示例13: GetLoader

        InnerAssemblyLoader GetLoader()
        {
            if( !reflectionOnly ) return new InnerAssemblyLoader();

            childDomain = BuildChildDomain(AppDomain.CurrentDomain);

            var loaderType = typeof(InnerAssemblyLoader);

            var loader =
                (InnerAssemblyLoader)
                childDomain.CreateInstanceFrom(loaderType.Assembly.Location, loaderType.FullName)
                .Unwrap();

            return loader;
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:15,代码来源:DirectoryAssemblyDiscovery.cs


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