ObjRef コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ObjRef クラスの新しいインスタンスを初期化します。
オーバーロード
ObjRef() |
ObjRef クラスの新しいインスタンスを既定値で初期化します。 |
ObjRef(MarshalByRefObject, Type) |
指定した ObjRef の指定した MarshalByRefObject を参照して、Type クラスの新しいインスタンスを初期化します。 |
ObjRef(SerializationInfo, StreamingContext) |
シリアル化したデータから、ObjRef クラスの新しいインスタンスを初期化します。 |
ObjRef()
ObjRef(MarshalByRefObject, Type)
指定した ObjRef の指定した MarshalByRefObject を参照して、Type クラスの新しいインスタンスを初期化します。
public:
ObjRef(MarshalByRefObject ^ o, Type ^ requestedType);
public ObjRef (MarshalByRefObject o, Type requestedType);
[System.Security.SecurityCritical]
public ObjRef (MarshalByRefObject o, Type requestedType);
new System.Runtime.Remoting.ObjRef : MarshalByRefObject * Type -> System.Runtime.Remoting.ObjRef
[<System.Security.SecurityCritical>]
new System.Runtime.Remoting.ObjRef : MarshalByRefObject * Type -> System.Runtime.Remoting.ObjRef
Public Sub New (o As MarshalByRefObject, requestedType As Type)
パラメーター
新しい ObjRef インスタンスが参照するオブジェクト。
- 属性
例
// a custom ObjRef class that outputs its status
[System::Security::Permissions::SecurityPermissionAttribute(
System::Security::Permissions::SecurityAction::Demand,
Flags=System::Security::Permissions::SecurityPermissionFlag::SerializationFormatter)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::Demand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::InheritanceDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
public ref class MyObjRef: public ObjRef
{
private:
// only instantiate via marshaling or deserialization
MyObjRef(){}
public:
MyObjRef( MarshalByRefObject^ o, Type^ t )
: ObjRef( o, t )
{
Console::WriteLine( "Created MyObjRef." );
ORDump();
}
MyObjRef( SerializationInfo^ i, StreamingContext c )
: ObjRef( i, c )
{
Console::WriteLine( "Deserialized MyObjRef." );
}
virtual void GetObjectData( SerializationInfo^ s, StreamingContext c ) override
{
// After calling the base method, change the type from ObjRef to MyObjRef
ObjRef::GetObjectData( s, c );
s->SetType( GetType() );
Console::WriteLine( "Serialized MyObjRef." );
}
virtual Object^ GetRealObject( StreamingContext context ) override
{
if ( IsFromThisAppDomain() || IsFromThisProcess() )
{
Console::WriteLine( "Returning actual Object* referenced by MyObjRef." );
return ObjRef::GetRealObject( context );
}
else
{
Console::WriteLine( "Returning proxy to remote Object*." );
return RemotingServices::Unmarshal( this );
}
}
void ORDump()
{
Console::WriteLine( " --- Reporting MyObjRef Info --- " );
Console::WriteLine( "Reference to {0}.", TypeInfo->TypeName );
Console::WriteLine( "URI is {0}.", URI );
Console::WriteLine( "\nWriting EnvoyInfo: " );
if ( EnvoyInfo != nullptr )
{
IMessageSink^ EISinks = EnvoyInfo->EnvoySinks;
while ( EISinks != nullptr )
{
Console::WriteLine( "\tSink: {0}", EISinks );
EISinks = EISinks->NextSink;
}
}
else
Console::WriteLine( "\t {no sinks}" );
Console::WriteLine( "\nWriting ChannelInfo: " );
for ( int i = 0; i < ChannelInfo->ChannelData->Length; i++ )
Console::WriteLine( "\tChannel: {0}", ChannelInfo->ChannelData[ i ] );
Console::WriteLine( " ----------------------------- " );
}
};
// a class that uses MyObjRef
public ref class LocalObject: public MarshalByRefObject
{
public:
// overriding CreateObjRef will allow us to return a custom ObjRef
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::LinkDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
virtual ObjRef^ CreateObjRef( Type^ t ) override
{
return gcnew MyObjRef( this,t );
}
};
// a custom ObjRef class that outputs its status
public class MyObjRef : ObjRef {
// only instantiate via marshaling or deserialization
private MyObjRef() { }
public MyObjRef(MarshalByRefObject o, Type t) : base(o, t) {
Console.WriteLine("Created MyObjRef.");
ORDump();
}
public MyObjRef(SerializationInfo i, StreamingContext c) : base(i, c) {
Console.WriteLine("Deserialized MyObjRef.");
}
public override void GetObjectData(SerializationInfo s, StreamingContext c) {
// After calling the base method, change the type from ObjRef to MyObjRef
base.GetObjectData(s, c);
s.SetType(GetType());
Console.WriteLine("Serialized MyObjRef.");
}
public override Object GetRealObject(StreamingContext context) {
if ( IsFromThisAppDomain() || IsFromThisProcess() ) {
Console.WriteLine("Returning actual object referenced by MyObjRef.");
return base.GetRealObject(context);
}
else {
Console.WriteLine("Returning proxy to remote object.");
return RemotingServices.Unmarshal(this);
}
}
public void ORDump() {
Console.WriteLine(" --- Reporting MyObjRef Info --- ");
Console.WriteLine("Reference to {0}.", TypeInfo.TypeName);
Console.WriteLine("URI is {0}.", URI);
Console.WriteLine("\nWriting EnvoyInfo: ");
if ( EnvoyInfo != null) {
IMessageSink EISinks = EnvoyInfo.EnvoySinks;
while (EISinks != null) {
Console.WriteLine("\tSink: " + EISinks.ToString());
EISinks = EISinks.NextSink;
}
}
else
{
Console.WriteLine("\t {no sinks}");
}
Console.WriteLine("\nWriting ChannelInfo: ");
for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
Console.WriteLine ("\tChannel: {0}", ChannelInfo.ChannelData[i]);
Console.WriteLine(" ----------------------------- ");
}
}
// a class that uses MyObjRef
public class LocalObject : MarshalByRefObject {
// overriding CreateObjRef will allow us to return a custom ObjRef
public override ObjRef CreateObjRef(Type t) {
return new MyObjRef(this, t);
}
}
適用対象
ObjRef(SerializationInfo, StreamingContext)
シリアル化したデータから、ObjRef クラスの新しいインスタンスを初期化します。
protected:
ObjRef(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ObjRef (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Security.SecurityCritical]
protected ObjRef (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Runtime.Remoting.ObjRef : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Runtime.Remoting.ObjRef
[<System.Security.SecurityCritical>]
new System.Runtime.Remoting.ObjRef : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Runtime.Remoting.ObjRef
Protected Sub New (info As SerializationInfo, context As StreamingContext)
パラメーター
- info
- SerializationInfo
シリアル化されたオブジェクト データを保持するオブジェクト。
- context
- StreamingContext
例外の発生元または発生先に関するコンテキスト情報。
- 属性
例
// a custom ObjRef class that outputs its status
[System::Security::Permissions::SecurityPermissionAttribute(
System::Security::Permissions::SecurityAction::Demand,
Flags=System::Security::Permissions::SecurityPermissionFlag::SerializationFormatter)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::Demand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::InheritanceDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
public ref class MyObjRef: public ObjRef
{
private:
// only instantiate via marshaling or deserialization
MyObjRef(){}
public:
MyObjRef( MarshalByRefObject^ o, Type^ t )
: ObjRef( o, t )
{
Console::WriteLine( "Created MyObjRef." );
ORDump();
}
MyObjRef( SerializationInfo^ i, StreamingContext c )
: ObjRef( i, c )
{
Console::WriteLine( "Deserialized MyObjRef." );
}
virtual void GetObjectData( SerializationInfo^ s, StreamingContext c ) override
{
// After calling the base method, change the type from ObjRef to MyObjRef
ObjRef::GetObjectData( s, c );
s->SetType( GetType() );
Console::WriteLine( "Serialized MyObjRef." );
}
virtual Object^ GetRealObject( StreamingContext context ) override
{
if ( IsFromThisAppDomain() || IsFromThisProcess() )
{
Console::WriteLine( "Returning actual Object* referenced by MyObjRef." );
return ObjRef::GetRealObject( context );
}
else
{
Console::WriteLine( "Returning proxy to remote Object*." );
return RemotingServices::Unmarshal( this );
}
}
void ORDump()
{
Console::WriteLine( " --- Reporting MyObjRef Info --- " );
Console::WriteLine( "Reference to {0}.", TypeInfo->TypeName );
Console::WriteLine( "URI is {0}.", URI );
Console::WriteLine( "\nWriting EnvoyInfo: " );
if ( EnvoyInfo != nullptr )
{
IMessageSink^ EISinks = EnvoyInfo->EnvoySinks;
while ( EISinks != nullptr )
{
Console::WriteLine( "\tSink: {0}", EISinks );
EISinks = EISinks->NextSink;
}
}
else
Console::WriteLine( "\t {no sinks}" );
Console::WriteLine( "\nWriting ChannelInfo: " );
for ( int i = 0; i < ChannelInfo->ChannelData->Length; i++ )
Console::WriteLine( "\tChannel: {0}", ChannelInfo->ChannelData[ i ] );
Console::WriteLine( " ----------------------------- " );
}
};
// a class that uses MyObjRef
public ref class LocalObject: public MarshalByRefObject
{
public:
// overriding CreateObjRef will allow us to return a custom ObjRef
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::LinkDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
virtual ObjRef^ CreateObjRef( Type^ t ) override
{
return gcnew MyObjRef( this,t );
}
};
// a custom ObjRef class that outputs its status
public class MyObjRef : ObjRef {
// only instantiate via marshaling or deserialization
private MyObjRef() { }
public MyObjRef(MarshalByRefObject o, Type t) : base(o, t) {
Console.WriteLine("Created MyObjRef.");
ORDump();
}
public MyObjRef(SerializationInfo i, StreamingContext c) : base(i, c) {
Console.WriteLine("Deserialized MyObjRef.");
}
public override void GetObjectData(SerializationInfo s, StreamingContext c) {
// After calling the base method, change the type from ObjRef to MyObjRef
base.GetObjectData(s, c);
s.SetType(GetType());
Console.WriteLine("Serialized MyObjRef.");
}
public override Object GetRealObject(StreamingContext context) {
if ( IsFromThisAppDomain() || IsFromThisProcess() ) {
Console.WriteLine("Returning actual object referenced by MyObjRef.");
return base.GetRealObject(context);
}
else {
Console.WriteLine("Returning proxy to remote object.");
return RemotingServices.Unmarshal(this);
}
}
public void ORDump() {
Console.WriteLine(" --- Reporting MyObjRef Info --- ");
Console.WriteLine("Reference to {0}.", TypeInfo.TypeName);
Console.WriteLine("URI is {0}.", URI);
Console.WriteLine("\nWriting EnvoyInfo: ");
if ( EnvoyInfo != null) {
IMessageSink EISinks = EnvoyInfo.EnvoySinks;
while (EISinks != null) {
Console.WriteLine("\tSink: " + EISinks.ToString());
EISinks = EISinks.NextSink;
}
}
else
{
Console.WriteLine("\t {no sinks}");
}
Console.WriteLine("\nWriting ChannelInfo: ");
for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
Console.WriteLine ("\tChannel: {0}", ChannelInfo.ChannelData[i]);
Console.WriteLine(" ----------------------------- ");
}
}
// a class that uses MyObjRef
public class LocalObject : MarshalByRefObject {
// overriding CreateObjRef will allow us to return a custom ObjRef
public override ObjRef CreateObjRef(Type t) {
return new MyObjRef(this, t);
}
}
注釈
このコンストラクターは、シリアル化解除の際に呼び出されて、ストリームで送信された例外オブジェクトを再構成します。 詳細については、「ISerializable」を参照してください。
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET