Browse Source

添加创建Domain工具类

yuzhengyang 9 years ago
parent
commit
9e6fbacc19
2 changed files with 40 additions and 0 deletions
  1. 39 0
      Fork.Net/Y.Utils/ReflectionUtils/DomainTool.cs
  2. 1 0
      Fork.Net/Y.Utils/Y.Utils.csproj

+ 39 - 0
Fork.Net/Y.Utils/ReflectionUtils/DomainTool.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Y.Utils.LogUtils;
+
+namespace Y.Utils.ReflectionUtils
+{
+    public static class DomainTool
+    {
+        public static AppDomain CreateDomain(string friendlyName)
+        {
+            try
+            {
+                //AppDomainSetup setup = new AppDomainSetup();
+                //setup.ApplicationName = "Test";
+                //setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
+                //setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory + "Private";
+                //setup.CachePath = setup.ApplicationBase;
+                //setup.ShadowCopyFiles = "true";
+                //setup.ShadowCopyDirectories = setup.ApplicationBase;
+                //AppDomain appDomain = AppDomain.CreateDomain("TestDomain", null, setup);
+                AppDomain appDomain = AppDomain.CreateDomain(friendlyName);
+                return appDomain;
+            }
+            catch (Exception e)
+            {
+                Log.e(e.Message);
+            }
+            return null;
+        }
+        public static T CreateInstance<T>(AppDomain domain)
+        {
+            T obj = (T)domain.CreateInstanceAndUnwrap(typeof(T).Assembly.FullName, typeof(T).FullName);
+            return obj;
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -80,6 +80,7 @@
     <Compile Include="FileUtils\FileTool.cs" />
     <Compile Include="BaseUtils\ListTool.cs" />
     <Compile Include="JsonUtils\JsonTool.cs" />
+    <Compile Include="ReflectionUtils\DomainTool.cs" />
     <Compile Include="ReflectionUtils\SimpleReflection.cs" />
     <Compile Include="TxtUtils\IniTool.cs" />
     <Compile Include="TxtUtils\LogTool.cs" />