AppDomain과 Activator의 차이점을 알고 싶습니다. appdomain.CreateInstance를 통해 DLL을로드했습니다. 하지만 인스턴스를 만드는 더 많은 방법을 깨달았습니다. 따라서 언제 또는 어디에서이 방법을 선택합니까? 예 1 :AppDomain.CreateInstance와 Activator.CreateInstance의 차이점은 무엇입니까?
// Use the file name to load the assembly into the current
// application domain.
Assembly a = Assembly.Load("example");
// Get the type to use.
Type myType = a.GetType("Example");
// Get the method to call.
MethodInfo myMethod = myType.GetMethod("MethodA");
// Create an instance.
object obj = Activator.CreateInstance(myType);
// Execute the method.
myMethod.Invoke(obj, null);
예 2 :
public WsdlClassParser CreateWsdlClassParser()
{
this.CreateAppDomain(null);
string AssemblyPath = Assembly.GetExecutingAssembly().Location;
WsdlClassParser parser = null;
try
{
parser = (WsdlClassParser) this.LocalAppDomain.CreateInstanceFrom(AssemblyPath,
typeof(Westwind.WebServices.WsdlClassParser).FullName).Unwrap() ;
}
catch (Exception ex)
{
this.ErrorMessage = ex.Message;
}
return parser;
}
예 3 : 좀 더 방법이 필요하거나의 차이는 무엇인가 왜
private static void InstantiateMyTypeSucceed(AppDomain domain)
{
try
{
string asmname = Assembly.GetCallingAssembly().FullName;
domain.CreateInstance(asmname, "MyType");
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(e.Message);
}
}
당신이 설명 할 수 있습니까?