ProxyAttribute 클래스
사용자 지정 프록시가 필요한 개체 형식을 나타냅니다.
네임스페이스: System.Runtime.Remoting.Proxies
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False, Inherited:=True)> _
Public Class ProxyAttribute
Inherits Attribute
Implements IContextAttribute
‘사용 방법
Dim instance As ProxyAttribute
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class ProxyAttribute : Attribute, IContextAttribute
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=false, Inherited=true)]
public ref class ProxyAttribute : public Attribute, IContextAttribute
/** @attribute ComVisibleAttribute(true) */
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) */
public class ProxyAttribute extends Attribute implements IContextAttribute
ComVisibleAttribute(true)
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true)
public class ProxyAttribute extends Attribute implements IContextAttribute
설명
사용자 지정 프록시가 필요한 형식에 현재 특성을 적용합니다. ProxyAttribute 클래스를 사용하면 ProxyAttribute에서 특성을 추출하고 이 특성을 ContextBoundObject의 자식에 넣어 new(Visual Basic: New) 문을 차단할 수 있습니다. 프록시 특성을 MarshalByRefObject의 자식에 넣는 것은 지원되지 않습니다.
참고
이 클래스는 클래스 수준에 링크 요청과 상속 요청을 만듭니다. 직접 실행 호출자나 파생 클래스에 인프라 권한이 없으면 SecurityException이 throw됩니다. 보안 요청에 대한 자세한 내용은 링크 요청 및 상속 요청을 참조하십시오.
예제
<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure), _
AttributeUsage(AttributeTargets.Class)> _
Public Class MyProxyAttribute
Inherits ProxyAttribute
Public Sub New()
End Sub 'New
' Create an instance of ServicedComponentProxy
Public Overrides Function CreateInstance(serverType As Type) As MarshalByRefObject
Return MyBase.CreateInstance(serverType)
End Function 'CreateInstance
Public Overrides Function CreateProxy(objRef1 As ObjRef, serverType As Type, _
serverObject As Object, serverContext As Context) As RealProxy
Dim myCustomProxy As New MyProxy(serverType)
If Not (serverContext Is Nothing) Then
RealProxy.SetStubData(myCustomProxy, serverContext)
End If
If Not serverType.IsMarshalByRef And serverContext Is Nothing Then
Throw New RemotingException("Bad Type for CreateProxy")
End If
Return myCustomProxy
End Function 'CreateProxy
End Class 'MyProxyAttribute
<MyProxyAttribute()> _
Public Class CustomServer
Inherits ContextBoundObject
Public Sub New()
Console.WriteLine("CustomServer Base Class constructor called")
End Sub 'New
Public Sub HelloMethod(str As String)
Console.WriteLine("HelloMethod of Server is invoked with message : " + str)
End Sub 'HelloMethod
End Class 'CustomServer
[AttributeUsage(AttributeTargets.Class)]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.Infrastructure)]
public class MyProxyAttribute : ProxyAttribute
{
public MyProxyAttribute()
{
}
// Create an instance of ServicedComponentProxy
public override MarshalByRefObject CreateInstance(Type serverType)
{
return base.CreateInstance(serverType);
}
public override RealProxy CreateProxy(ObjRef objRef1,
Type serverType,
object serverObject,
Context serverContext)
{
MyProxy myCustomProxy = new MyProxy(serverType);
if(serverContext != null)
{
RealProxy.SetStubData(myCustomProxy,serverContext);
}
if((!serverType.IsMarshalByRef)&&(serverContext == null))
{
throw new RemotingException("Bad Type for CreateProxy");
}
return myCustomProxy;
}
}
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
[MyProxyAttribute]
public class CustomServer :ContextBoundObject
{
public CustomServer()
{
Console.WriteLine("CustomServer Base Class constructor called");
}
public void HelloMethod(string str)
{
Console.WriteLine("HelloMethod of Server is invoked with message : " + str);
}
}
[AttributeUsageAttribute(AttributeTargets::Class)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::LinkDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::InheritanceDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
public ref class MyProxyAttribute: public ProxyAttribute
{
public:
MyProxyAttribute(){}
// Create an instance of ServicedComponentProxy
virtual MarshalByRefObject^ CreateInstance( Type^ serverType ) override
{
return ProxyAttribute::CreateInstance( serverType );
}
virtual RealProxy^ CreateProxy( ObjRef^ objRef1, Type^ serverType, Object^ serverObject, Context^ serverContext ) override
{
MyProxy^ myCustomProxy = gcnew MyProxy( serverType );
if ( serverContext != nullptr )
{
RealProxy::SetStubData( myCustomProxy, serverContext );
}
if ( ( !serverType->IsMarshalByRef) && (serverContext == nullptr) )
{
throw gcnew RemotingException( "Bad Type for CreateProxy" );
}
return myCustomProxy;
}
};
[MyProxyAttribute]
ref class CustomServer: public ContextBoundObject
{
public:
CustomServer()
{
Console::WriteLine( "CustomServer Base Class constructor called" );
}
void HelloMethod( String^ str )
{
Console::WriteLine( "HelloMethod of Server is invoked with message : {0}", str );
}
};
.NET Framework 보안
- SecurityPermission 인프라 코드를 사용하여 작업하는 데 필요한 권한입니다. 요청 값: SecurityAction.LinkDemand; 권한 값: SecurityPermissionFlag.Infrastructure
- SecurityPermission 인프라 코드를 사용하여 작업하는 데 필요한 권한입니다. 요청 값: SecurityAction.InheritanceDemand; 권한 값: SecurityPermissionFlag.Infrastructure
상속 계층 구조
System.Object
System.Attribute
System.Runtime.Remoting.Proxies.ProxyAttribute
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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에서 지원
참고 항목
참조
ProxyAttribute 멤버
System.Runtime.Remoting.Proxies 네임스페이스
RealProxy