Share via


Activator 클래스

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

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public NotInheritable Class Activator
    Implements _Activator
‘사용 방법
Dim instance As Activator
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
public sealed class Activator : _Activator
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
public ref class Activator sealed : _Activator
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
public final class Activator implements _Activator
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.None) 
public final class Activator implements _Activator

설명

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

생성자를 검색하고 호출할 수 있는 권한이 없으면 예외가 throw됩니다. 기본적으로 생성자를 검색할 때에는 public 생성자만 검색됩니다. 생성자가 없거나 기본 생성자를 찾을 수 없는 경우 예외가 throw됩니다.

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

증명 매개 변수는 생성자의 보안 정책 및 권한에 영향을 미칩니다. 자세한 내용은 System.Security.Policy.Evidence 클래스를 참조하십시오.

형식의 인스턴스는 로컬 또는 원격 사이트에서 만들 수 있습니다. 형식을 원격으로 만든 경우에는 활성화 특성 매개 변수가 원격 사이트의 URI를 지정합니다. 인스턴스 만들기 요청은 원격 사이트에 도달하기 전에 중개 사이트를 통과할 수도 있습니다. 다른 활성화 특성으로 인해 원격 및 중개 역할 사이트에 요청이 작동하는 환경이나 컨텍스트가 수정될 수 있습니다.

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

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

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

서버에서 활성화한 개체와 클라이언트에서 활성화한 개체에 대한 자세한 내용은 서버 활성화 항목을 참조하십시오.

예제

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

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 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

상속 계층 구조

System.Object
  System.Activator

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Activator 멤버
System 네임스페이스

기타 리소스

.NET Framework Remoting 개요