Activator 클래스

정의

개체의 형식을 로컬 또는 원격으로 만들거나 기존 원격 개체에 대한 참조를 얻는 메서드를 포함합니다. 이 클래스는 상속될 수 없습니다.

public ref class Activator abstract sealed
public ref class Activator sealed : System::Runtime::InteropServices::_Activator
public static class Activator
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class Activator : System.Runtime.InteropServices._Activator
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Activator : System.Runtime.InteropServices._Activator
type Activator = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type Activator = class
    interface _Activator
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Activator = class
    interface _Activator
Public Class Activator
Public NotInheritable Class Activator
Implements _Activator
상속
Activator
특성
구현

예제

다음 예제에서는 사용 Activator 하는 방법을 보여 줍니다는 클래스를 동적으로 생성 하는 런타임에 개체입니다.

using namespace System;
using namespace System::Reflection;
using namespace System::Text;

public ref class SomeType
{
public:
    void DoSomething(int x)
    {
        Console::WriteLine("100 / {0} = {1}", x, 100 / x);
    }
};

void main()
{
    // Create an instance of the StringBuilder type using 
    // Activator.CreateInstance.
    Object^ o = Activator::CreateInstance(StringBuilder::typeid);

    // Append a string into the StringBuilder object and display the 
    // StringBuilder.
    StringBuilder^ sb = (StringBuilder^) o;
    sb->Append("Hello, there.");
    Console::WriteLine(sb);

    // Create an instance of the SomeType class that is defined in this 
    // assembly.
    System::Runtime::Remoting::ObjectHandle^ oh = 
        Activator::CreateInstanceFrom(Assembly::GetEntryAssembly()->CodeBase, 
                                      SomeType::typeid->FullName);

    // Call an instance method defined by the SomeType type using this object.
    SomeType^ st = (SomeType^) oh->Unwrap();

    st->DoSomething(5);
};

/* This code produces the following output:
 
Hello, there.
100 / 5 = 20
 */
using System;
using System.Reflection;
using System.Text;

public class SomeType
{
    public void DoSomething(int x)
    {
        Console.WriteLine("100 / {0} = {1}", x, 100 / x);
    }
}

public class Example
{
    static void Main()
    {
        // Create an instance of the StringBuilder type using
        // Activator.CreateInstance.
        Object o = Activator.CreateInstance(typeof(StringBuilder));

        // Append a string into the StringBuilder object and display the
        // StringBuilder.
        StringBuilder sb = (StringBuilder) o;
        sb.Append("Hello, there.");
        Console.WriteLine(sb);

        // Create an instance of the SomeType class that is defined in this
        // assembly.
        System.Runtime.Remoting.ObjectHandle oh =
            Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase,
                                         typeof(SomeType).FullName);

        // Call an instance method defined by the SomeType type using this object.
        SomeType st = (SomeType) oh.Unwrap();

        st.DoSomething(5);
    }
}

/* This code produces the following output:

Hello, there.
100 / 5 = 20
 */
open System
open System.Reflection
open System.Text

type SomeType() =
    member _.DoSomething(x) = printfn $"100 / {x} = {100 / x}"

// Create an instance of the StringBuilder type using Activator.CreateInstance.
let o = Activator.CreateInstance typeof<StringBuilder>

// Append a string into the StringBuilder object and display the StringBuilder.
let sb = o :?> StringBuilder
sb.Append "Hello, there." |> ignore
printfn $"{sb}"

// Create an instance of the SomeType class that is defined in this assembly.
let oh = 
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().Location, typeof<SomeType>.FullName)

// Call an instance method defined by the SomeType type using this object.
let st = oh.Unwrap() :?> SomeType

st.DoSomething 5

(* This code produces the following output:

Hello, there.
100 / 5 = 20
 *)
Imports System.Reflection
Imports System.Text

Module Module1
    Sub Main()
        ' Create an instance of the StringBuilder type using 
        ' Activator.CreateInstance.
        Dim o As Object = Activator.CreateInstance(GetType(StringBuilder))

        ' Append a string into the StringBuilder object and display the 
        ' StringBuilder.
        Dim sb As StringBuilder = CType(o, StringBuilder)
        sb.Append("Hello, there.")
        Console.WriteLine(sb)

        ' Create an instance of the SomeType class that is defined in this assembly.
        Dim oh As System.Runtime.Remoting.ObjectHandle = _
            Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, _
                                         GetType(SomeType).FullName)

        ' Call an instance method defined by the SomeType type using this object.
        Dim st As SomeType = CType(oh.Unwrap(), SomeType)

        st.DoSomething(5)
    End Sub

    Class SomeType
        Public Sub DoSomething(ByVal x As Int32)
            Console.WriteLine("100 / {0} = {1}", x, 100 \ x)
        End Sub
    End Class
End Module

' This code produces the following output:
' 
' Hello, there.
' 100 / 5 = 20

설명

메서드는 CreateInstance 지정된 인수와 가장 일치하는 생성자를 호출하여 어셈블리에 정의된 형식의 인스턴스를 만듭니다. 인수를 지정하지 않으면 매개 변수를 사용하지 않는 생성자, 즉 매개 변수가 없는 생성자가 호출됩니다.

생성자를 검색하고 호출할 수 있는 충분한 권한이 있어야 합니다. 그렇지 않으면 예외가 throw됩니다. 기본적으로 공용 생성자만 생성자를 검색하는 동안 고려됩니다. 생성자 또는 매개 변수가 없는 생성자를 찾을 수 없는 경우 예외가 throw됩니다.

바인더 매개 변수는 어셈블리에서 적합한 생성자를 검색하는 개체를 지정합니다. 고유한 바인더 및 검색 조건을 지정할 수 있습니다. 바인더를 지정하지 않으면 기본 바인더가 사용됩니다. 자세한 내용은 System.Reflection.BinderSystem.Reflection.BindingFlags 클래스를 참조하세요.

evidence 매개 변수는 생성자에 대한 보안 정책 및 권한에 영향을 줍니다. 자세한 내용은 System.Security.Policy.Evidence 클래스를 참조하세요.

형식의 인스턴스는 로컬 또는 원격 사이트에서 만들 수 있습니다. 형식이 원격으로 만들어지면 활성화 특성 매개 변수는 원격 사이트의 URI를 지정합니다. 인스턴스를 만들기 위한 호출은 원격 사이트에 도달하기 전에 중간 사이트를 통과할 수 있습니다. 다른 활성화 특성은 원격 및 중간 사이트에서 호출이 작동하는 환경 또는 컨텍스트를 수정할 수 있습니다.

인스턴스가 로컬로 만들어지면 해당 개체에 대한 참조가 반환됩니다. 인스턴스가 원격으로 만들어지면 프록시에 대한 참조가 반환됩니다. 원격 개체는 마치 로컬 개체인 것처럼 프록시를 통해 조작됩니다.

메서드는 GetObject 현재 실행 중인 원격 개체, 서버 활성화 잘 알려진 개체 또는 XML 웹 서비스에 대한 프록시를 만듭니다. 연결 매체, 즉 채널을 지정할 수 있습니다. 자세한 내용은 System.Runtime.Remoting.Channels.ChannelServices 클래스를 참조하세요.

어셈블리에는 형식 정의가 포함되어 있습니다. 메서드는 CreateInstance 현재 실행 중인 어셈블리에서 형식의 인스턴스를 만듭니다. 메서드는 CreateInstanceFrom 어셈블리가 포함된 파일에서 인스턴스를 만듭니다. 메서드는 CreateComInstanceFrom 어셈블리가 포함된 파일에서 COM 개체의 인스턴스를 만듭니다.

메서드

CreateComInstanceFrom(String, String)

명명된 어셈블리 파일 및 매개 변수가 없는 생성자를 사용하여 이름이 지정된 COM 개체의 인스턴스를 만듭니다.

CreateComInstanceFrom(String, String, Byte[], AssemblyHashAlgorithm)

명명된 어셈블리 파일 및 매개 변수가 없는 생성자를 사용하여 이름이 지정된 COM 개체의 인스턴스를 만듭니다.

CreateInstance(ActivationContext)

지정된 ActivationContext 개체에서 지정하는 형식의 인스턴스를 만듭니다.

CreateInstance(ActivationContext, String[])

지정된 사용자 지정 활성화 데이터로 활성화되며 지정된 ActivationContext 개체에서 지정하는 형식의 인스턴스를 만듭니다.

CreateInstance(AppDomain, String, String)

명명된 어셈블리 및 매개 변수가 없는 생성자를 사용하여 지정된 원격 도메인에 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

명명된 어셈블리 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 지정된 원격 도메인에 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
사용되지 않음.

명명된 어셈블리 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 지정된 원격 도메인에 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(String, String)

명명된 어셈블리 및 매개 변수가 없는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

명명된 어셈블리 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
사용되지 않음.

명명된 어셈블리 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(String, String, Object[])

명명된 어셈블리 및 매개 변수가 없는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(Type)

해당 형식의 매개 변수가 없는 생성자를 사용하여 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo)

지정한 매개 변수와 가장 일치하는 생성자를 사용하여 지정한 유형의 인스턴스를 만듭니다.

CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[])

지정한 매개 변수와 가장 일치하는 생성자를 사용하여 지정한 유형의 인스턴스를 만듭니다.

CreateInstance(Type, Boolean)

해당 형식의 매개 변수가 없는 생성자를 사용하여 지정된 형식의 인스턴스를 만듭니다.

CreateInstance(Type, Object[])

지정한 매개 변수와 가장 일치하는 생성자를 사용하여 지정한 유형의 인스턴스를 만듭니다.

CreateInstance(Type, Object[], Object[])

지정한 매개 변수와 가장 일치하는 생성자를 사용하여 지정한 유형의 인스턴스를 만듭니다.

CreateInstance<T>()

매개 변수가 없는 생성자를 사용하여 지정된 제네릭 형식 매개 변수로 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(AppDomain, String, String)

명명된 어셈블리 파일 및 매개 변수가 없는 생성자를 사용하여 지정된 원격 도메인에 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

명명된 어셈블리 파일 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 지정된 원격 도메인에 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
사용되지 않음.

명명된 어셈블리 파일 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 지정된 원격 도메인에 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(String, String)

명명된 어셈블리 파일 및 매개 변수가 없는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

명명된 어셈블리 파일 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
사용되지 않음.

명명된 어셈블리 파일 및 지정된 매개 변수와 가장 일치하는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

CreateInstanceFrom(String, String, Object[])

명명된 어셈블리 파일 및 매개 변수가 없는 생성자를 사용하여 이름이 지정된 형식의 인스턴스를 만듭니다.

GetObject(Type, String)

지정된 형식 및 URL로 표시되는 잘 알려진 개체의 프록시를 만듭니다.

GetObject(Type, String, Object)

지정된 형식, URL 및 채널 데이터로 표시되는 잘 알려진 개체의 프록시를 만듭니다.

명시적 인터페이스 구현

_Activator.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

_Activator.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

_Activator.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

_Activator.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

적용 대상