ObjRef.IsFromThisAppDomain メソッド
現在の ObjRef インスタンスが現在の AppDomain にあるオブジェクトを参照しているかどうかを示すブール値を返します。
Public Function IsFromThisAppDomain() As Boolean
[C#]
public bool IsFromThisAppDomain();
[C++]
public: bool IsFromThisAppDomain();
[JScript]
public function IsFromThisAppDomain() : Boolean;
戻り値
現在の ObjRef インスタンスが現在の AppDomain にあるオブジェクトを参照しているかどうかを示すブール値。
使用例
// 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);
}
}
[C++]
// a custom ObjRef class that outputs its status
public __gc class MyObjRef : public ObjRef
{
// only instantiate via marshaling or deserialization
private:
MyObjRef() { }
public:
MyObjRef(MarshalByRefObject* o, Type* t) : ObjRef(o, t)
{
Console::WriteLine(S"Created MyObjRef.");
ORDump();
}
public:
MyObjRef(SerializationInfo* i, StreamingContext c) : ObjRef(i, c)
{
Console::WriteLine(S"Deserialized MyObjRef.");
}
public:
void GetObjectData(SerializationInfo* s, StreamingContext c)
{
// After calling the base method, change the type from ObjRef to MyObjRef
ObjRef::GetObjectData(s, c);
s->SetType(GetType());
Console::WriteLine(S"Serialized MyObjRef.");
}
public:
Object* GetRealObject(StreamingContext context)
{
if (IsFromThisAppDomain() || IsFromThisProcess())
{
Console::WriteLine(S"Returning actual Object* referenced by MyObjRef.");
return ObjRef::GetRealObject(context);
}
else
{
Console::WriteLine(S"Returning proxy to remote Object*.");
return RemotingServices::Unmarshal(this);
}
}
public:
void ORDump()
{
Console::WriteLine(S" --- Reporting MyObjRef Info --- ");
Console::WriteLine(S"Reference to {0}.", TypeInfo->TypeName);
Console::WriteLine(S"URI is {0}.", URI);
Console::WriteLine(S"\nWriting EnvoyInfo: ");
if (EnvoyInfo != 0)
{
IMessageSink* EISinks = EnvoyInfo->EnvoySinks;
while (EISinks != 0)
{
Console::WriteLine(S"\tSink: {0}", EISinks);
EISinks = EISinks->NextSink;
}
}
else
Console::WriteLine(S"\t {no sinks}");
Console::WriteLine(S"\nWriting ChannelInfo: ");
for (int i = 0; i < ChannelInfo->ChannelData->Length; i++)
Console::WriteLine (S"\tChannel: {0}", ChannelInfo->ChannelData->Item[i]);
Console::WriteLine(S" ----------------------------- ");
}
};
// a class that uses MyObjRef
public __gc class LocalObject : public MarshalByRefObject
{
// overriding CreateObjRef will allow us to return a custom ObjRef
public:
ObjRef* CreateObjRef(Type* t)
{
return new MyObjRef(this, t);
}
};
[Visual Basic, JScript] Visual Basic および JScript のサンプルはありません。C# および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ