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


C# AppDomain.CreateInstance方法代码示例

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


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

示例1: APIWrapper

        static APIWrapper()
        {
            _domain = AppDomain.CreateDomain("OPEN_TERRARIA_API_WRAPPER", null /*AppDomain.CurrentDomain.Evidence*/, new AppDomainSetup()
                {
                    //ShadowCopyFiles = "false",
                    ApplicationBase = Environment.CurrentDirectory/*, Commented out as OSX does not have this?
                    AppDomainManagerAssembly = String.Empty*/
                });

            var type = typeof(Proxy);
            foreach (var file in new string[] { "Patcher.exe", "OTA.dll" })
            {
                if (!System.IO.File.Exists(file))
                {
                    var bin = System.IO.Path.Combine(Environment.CurrentDirectory, "bin", "x86", "Debug", file);
                    if (System.IO.File.Exists(bin))
                    {
                        System.IO.File.Copy(bin, file);
                        Console.WriteLine("Copied: " + file);
                    }
                }
            }
            var plugin = _domain.CreateInstance(type.Assembly.FullName, type.FullName);
            _api = plugin.Unwrap() as Proxy;

            _api.Load(System.IO.Path.Combine(Environment.CurrentDirectory, "OTA.dll"));
        }
开发者ID:hastinbe,项目名称:Open-Terraria-API,代码行数:27,代码来源:APIWrapper.cs

示例2: CreateRemoteContainer

		protected IWindsorContainer CreateRemoteContainer(AppDomain domain, String configFile)
		{
			ObjectHandle handle = domain.CreateInstance( 
				typeof(WindsorContainer).Assembly.FullName, 
				typeof(WindsorContainer).FullName, false, BindingFlags.Instance|BindingFlags.Public, null, 
				new object[] { configFile }, 
				CultureInfo.InvariantCulture, null, null );

			return (IWindsorContainer) handle.Unwrap();
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:10,代码来源:AbstractRemoteTestCase.cs

示例3: GetRemoteContainer

		protected IWindsorContainer GetRemoteContainer(AppDomain domain, String configFile)
		{
			ObjectHandle handle = domain.CreateInstance( 
				typeof(ContainerPlaceHolder).Assembly.FullName, 
				typeof(ContainerPlaceHolder).FullName, false, BindingFlags.Instance|BindingFlags.Public, null, 
				new object[] { configFile }, 
				CultureInfo.InvariantCulture, null, null );

			ContainerPlaceHolder holder = handle.Unwrap() as ContainerPlaceHolder;

			return holder.Container;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:12,代码来源:AbstractRemoteTestCase.cs

示例4: LoadAssembly

        internal static IAssembly LoadAssembly(string path, AppDomain domain)
        {
            if (domain != AppDomain.CurrentDomain) {
                var crossDomainAssembly = domain.CreateInstance<RemoteAssembly>();
                crossDomainAssembly.Load(path);

                return crossDomainAssembly;
            }

            var assembly = new RemoteAssembly();
            assembly.Load(path);
            return assembly;
        }
开发者ID:jacksonh,项目名称:nuget,代码行数:13,代码来源:RemoteAssembly.cs

示例5: APIWrapper

        static APIWrapper()
        {
            //_domain = AppDomain.CreateDomain("TDSM_API_WRAPPER", AppDomain.CurrentDomain.Evidence, new AppDomainSetup()
            //{
            //    //ShadowCopyFiles = "false",
            //    ApplicationBase = Environment.CurrentDirectory
            //});
            _domain = AppDomain.CreateDomain("OPEN_TERRARIA_API_WRAPPER", null /*AppDomain.CurrentDomain.Evidence*/, new AppDomainSetup()
                {
                    //ShadowCopyFiles = "false",
                    ApplicationBase = Environment.CurrentDirectory/*, Commented out as OSX does not have this?
                AppDomainManagerAssembly = String.Empty*/
                });

            //Console.WriteLine("Domain: " + ((_domain == null) ? "null" : "not null"));

            //_domain.AssemblyResolve += (s, a) =>
            //{
            //    try
            //    {
            //        //return Assembly.LoadFrom(Path.Combine(Globals.PluginPath, a.Name + ".dll"));
            //    }
            //    catch { }
            //    return null;
            //};

            var type = typeof(Proxy);
            foreach (var file in new string[] { "Patcher.exe", "OTA.dll" })
            {
                if (!System.IO.File.Exists(file))
                {
                    var bin = System.IO.Path.Combine(Environment.CurrentDirectory, "bin", "x86", "Debug", file);
                    if (System.IO.File.Exists(bin))
                    {
                        System.IO.File.Copy(bin, file);
                        Console.WriteLine("Copied: " + file);
                    }
                }
            }
            var plugin = _domain.CreateInstance(type.Assembly.FullName, type.FullName);
            //            var r = plugin.CreateObjRef(typeof(MarshalByRefObject));
            ////var p = r.GetRealObject(new System.Runtime.Serialization.StreamingContext( System.Runtime.Serialization.StreamingContextStates.CrossAppDomain));
            _api = plugin.Unwrap() as Proxy;

            _api.Load(System.IO.Path.Combine(Environment.CurrentDirectory, "OTA.dll"));

            //var has = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.GetName().Name == "TDSM.API").Count() > 0;
            //var asm = _domain.GetAssemblies();
        }
开发者ID:tylerjwatson,项目名称:Open-Terraria-API,代码行数:49,代码来源:APIWrapper.cs

示例6: CreateInstance

        /// <summary>
        /// Returns a RemoteTestRunner in the target domain. This method
        /// is used in the domain that wants to get a reference to 
        /// a RemoteTestRunnner and not in the test domain itself.
        /// </summary>
        /// <param name="targetDomain">AppDomain in which to create the runner</param>
        /// <param name="ID">Id for the new runner to use</param>
        /// <returns></returns>
        public static RemoteTestRunner CreateInstance(AppDomain targetDomain, int ID)
        {
            #if NET_2_0
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(
                targetDomain,
            #else
            System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstance(
            #endif
                Assembly.GetExecutingAssembly().FullName,
                typeof(RemoteTestRunner).FullName,
                false, BindingFlags.Default, null, new object[] { ID }, null, null, null);

            object obj = oh.Unwrap();
            return (RemoteTestRunner)obj;
        }
开发者ID:scottwis,项目名称:eddie,代码行数:23,代码来源:RemoteTestRunner.cs

示例7: CreateInstance

        /// <summary>
        /// Factory method used to create a DomainAgent 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>
        static public DomainAgent CreateInstance(AppDomain targetDomain)
        {
#if CLR_2_0 || CLR_4_0
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(
                targetDomain,
#else
			System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstance(
#endif
 Assembly.GetExecutingAssembly().FullName,
                typeof(DomainAgent).FullName,
                false, BindingFlags.Default, null, null, null, null, null);

            object obj = oh.Unwrap();
            return (DomainAgent)obj;
        }
开发者ID:Vernathic,项目名称:ic-AutoTest.NET4CTDD,代码行数:21,代码来源:DomainAgent.cs

示例8: InstantiateDecimal

 static object InstantiateDecimal(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string UName, string P2PUri)
 {
     try
     {
         object instance = appDomain.CreateInstance(
            "ImageSharing.Presentation",
            "ImageSharing.Presentation.P2PImageSharingClient",
            false,
            BindingFlags.Default,
            binder,
            new object[] { UName, P2PUri },
            cultureInfo,
            null,
            null
         );
         return instance;
     }
     catch (Exception exp)
     {
         VMuktiHelper.ExceptionHandler(exp, "InstantiateDecimal", "P2PImageSharingDummyClient.cs");
         return null;
     }
 }
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:23,代码来源:P2PImageSharingDummyClient.cs

示例9: InstantiateQA

        static object InstantiateQA(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string MyName, string UName, int Id, string netP2pUri, string httpUri)
        {
            try
            {

                object instance = appDomain.CreateInstance(
                   "QA.Presentation",
                   "QA.Presentation.QADummy",
                   false,
                   BindingFlags.Default,
                   binder,
                   new object[] { MyName, UName, Id, netP2pUri, httpUri },
                   cultureInfo,
                   null,
                   null
                );
                return instance;
            }
            catch (Exception exp)
            {
                return null;
            }
        }
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:23,代码来源:DummyClient.cs

示例10: Start

 public void Start()
 {
     _Domain = AppDomain.CreateDomain(_Setup.ApplicationName, null, _Setup);
     // Construct the target class, it must take over from there.
     _RemoteType = _Domain.CreateInstance(_TypeInfo[1], _TypeInfo[0]);
 }
开发者ID:djMax,项目名称:AlienForce,代码行数:6,代码来源:HostedService.cs

示例11: CreateTestRunner

        private RemoteTestRunner CreateTestRunner(AppDomain domain)
        {
            ObjectHandle oh;
            Type rtrType = typeof(RemoteTestRunner);

            #if NET_4_0
            oh = domain.CreateInstance(
                rtrType.Assembly.FullName,
                rtrType.FullName,
                false,
                BindingFlags.Public | BindingFlags.Instance,
                null,
                null,
                CultureInfo.InvariantCulture,
                null);
            #else
            oh = domain.CreateInstance(
                rtrType.Assembly.FullName,
                rtrType.FullName,
                false,
                BindingFlags.Public | BindingFlags.Instance,
                null,
                null,
                CultureInfo.InvariantCulture,
                null,
                AppDomain.CurrentDomain.Evidence);
            #endif
            return (RemoteTestRunner) oh.Unwrap();
        }
开发者ID:radleta,项目名称:nant,代码行数:29,代码来源:NUnit2TestDomain.cs

示例12: InitializeKeyCheck

        //**************************************************************
        // InitializeKeyCheck()
        //**************************************************************
        public void InitializeKeyCheck()
        {
            //Clear any previous app domain
            UnInitializeKeyCheck();

            AD = AppDomain.CreateDomain("KeyValidatorDomain");

            BindingFlags flags = (BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance);

            ObjectHandle objh = AD.CreateInstance( "AppUpdater", "Microsoft.Samples.AppUpdater.KeyValidator", false,
                               flags, null, null, null, null, null);

            // Unwrap the object
            Object obj = objh.Unwrap();

            // Cast to the actual type
            Validator = (KeyValidator)obj;

            KeyList = GetKeyList(AppUrl.TrimEnd(new char[] {'/'}) + "/" + KEYFILENAME);
        }
开发者ID:nkasar,项目名称:HealthSmartStandAlone,代码行数:23,代码来源:AppKeys.cs

示例13: CreateAppDomain

		/// <summary>
		/// Initialize the AppDomain and load the types of the dll
		/// </summary>
		/// <returns>the types of the dll</returns>
		public void CreateAppDomain()
		{

			string currentDirectory = Environment.CurrentDirectory;
			string cachePath = Path.Combine(
				currentDirectory,
				"__cache");

			PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted);
			AppDomainSetup appDomainSetup = new AppDomainSetup
			{
				ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
				ShadowCopyFiles = "true",
				CachePath = cachePath
			};
			_testsDomain = AppDomain.CreateDomain("TestDomain", null, appDomainSetup, permissionSet);

			try
			{
                ITypesLoaderFactory typesLoaderFactory = (ITypesLoaderFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, " RegTesting.Tests.Core.TypesLoaderFactory").Unwrap();
				object[] constructArgs = new object[] { };
                ITypesLoader typesLoader = typesLoaderFactory.Create(Assembly.GetExecutingAssembly().FullName, " RegTesting.Tests.Core.TypesLoader", constructArgs);
				Types = typesLoader.GetTypes(_testsFile);
			}
			catch (NullReferenceException)
			{
			}

		}
开发者ID:florianwittmann,项目名称:regtesting,代码行数:33,代码来源:TestcaseProvider.cs

示例14: LoadTypes

		/// <summary>
		/// Initialize the AppDomain and load the types of the dll
		/// </summary>
		/// <returns>the types of the dll</returns>
		public string[] LoadTypes()
		{

			string environmentPath = Environment.CurrentDirectory;
			string cachePath = Path.Combine(environmentPath,"__cache");

			PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted);
			AppDomainSetup appDomainSetup = new AppDomainSetup
			                          	{
											ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
			                          		ShadowCopyFiles = "true",
			                          		CachePath = cachePath
			                          	};
			_testsDomain = AppDomain.CreateDomain("TestDomain", null, appDomainSetup, permissionSet);

			try
			{
                ITypesLoaderFactory typesLoaderFactory = (ITypesLoaderFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TypesLoaderFactory").Unwrap();
				object[] constructArgs = new object[] {};
                ITypesLoader typesLoader = typesLoaderFactory.Create(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TypesLoader", constructArgs);
				Types = typesLoader.GetTypes(_testsFile);
				foreach (string type in Types)
				{
					if (type.StartsWith("ERROR:"))
					{
						Console.WriteLine(type);
					}
				}
				return Types;
			}
			catch (NullReferenceException)
			{
				//No types found for this branch
				return new string[0];
			}
			catch (ReflectionTypeLoadException reflectionTypeLoadException)
			{
				StringBuilder stringBuilder = new StringBuilder();
				foreach (Exception exSub in reflectionTypeLoadException.LoaderExceptions)
				{
					stringBuilder.AppendLine(exSub.Message);
					if (exSub is FileNotFoundException)
					{
						FileNotFoundException fileNotFoundException = exSub as FileNotFoundException;
						if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog))
						{
							stringBuilder.AppendLine("Fusion Log:");
							stringBuilder.AppendLine(fileNotFoundException.FusionLog);
						}
					}
					stringBuilder.AppendLine();
				}
				string errorMessage = stringBuilder.ToString();
				Console.WriteLine(errorMessage);
				//Display or log the error based on your application.
				return new string[0];
			}
			catch (Exception exception)
			{
				Console.WriteLine(exception.ToString());
				//No types found for this branch
				return new string[0];
			}
		}
开发者ID:florianwittmann,项目名称:regtesting,代码行数:68,代码来源:TestcaseProvider.cs

示例15: InstantiateDecimal

        //static object InstantiateDecimal(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string MyName, string UName, int Id, string netP2pUri, string httpUri)
        //{
        //    try
        //    {
        //        object instance = appDomain.CreateInstance(
        //           "Weblink.Presentation",
        //           "Weblink.Presentation.WebLinkDummies",
        //           false,
        //           BindingFlags.Default,
        //           binder,
        //           new object[] { MyName, UName, Id, netP2pUri, httpUri },
        //           cultureInfo,
        //           null,
        //           null
        //        );
        //        return instance;
        //    }
        //    catch (Exception exp)
        //    {
        //        System.Windows.MessageBox.Show("InstantiateDecimal" + exp.Message);
        //        if (exp.InnerException != null)
        //        {
        //            System.Windows.MessageBox.Show("InstantiateDecimal " + exp.InnerException.Message);
        //        }
        //        throw exp;
        //        return null;
        //    }
        //}

        static object InstantiateDecimal(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string MyName, string UName, int Id, string netP2pUri, string httpUri)
        {
            try
            {

                object instance = appDomain.CreateInstance(
                   "Video.Presentation",
                   "Video.Presentation.MainVideoDummies",
                   false,
                   BindingFlags.Default,
                   binder,
                   new object[] { MyName, UName, Id, netP2pUri, httpUri },
                   cultureInfo,
                   null,
                   null
                );
                return instance;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "--InstantiateDecimal()---VMukti--:--VmuktiModules--:--Collaborative--:--Video.Presentation--:--MainVideoDummyClient.cs--:");
                //ClsException.LogError(ex);
                //ClsException.WriteToErrorLogFile(ex);
                System.Text.StringBuilder sb = new StringBuilder();
                sb.AppendLine(ex.Message);
                sb.AppendLine();
                sb.AppendLine("StackTrace : " + ex.StackTrace);
                sb.AppendLine();
                sb.AppendLine("Location : " + ex.Data["My Key"].ToString());
                sb.AppendLine();
                sb1 = CreateTressInfo();
                sb.Append(sb1.ToString());
                VMuktiAPI.ClsLogging.WriteToTresslog(sb);
                return null;
            }
        }
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:65,代码来源:MainVideoDummyClient.cs


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