Type.IsMarshalByRefImpl メソッド
IsMarshalByRef プロパティを実装し、 Type が参照渡しでマーシャリングされるかどうかを判断します。
Protected Overridable Function IsMarshalByRefImpl() As Boolean
[C#]
protected virtual bool IsMarshalByRefImpl();
[C++]
protected: virtual bool IsMarshalByRefImpl();
[JScript]
protected function IsMarshalByRefImpl() : Boolean;
戻り値
Type が参照渡しでマーシャリングされる場合は true 。それ以外の場合は false 。
解説
このメソッドは、派生クラスでオーバーライドできます。
使用例
[Visual Basic, C#, C++] 指定された型が参照渡しでマーシャリングされるかどうかを判断して結果を表示する例を次に示します。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyTypeDelegatorClass
Inherits TypeDelegator
Public myElementType As String = Nothing
Private myType As Type = Nothing
Public Sub New(ByVal myType As Type)
MyBase.New(myType)
Me.myType = myType
End Sub 'New
' Override IsMarshalByRefImpl.
Protected Overrides Function IsMarshalByRefImpl() As Boolean
' Determine whether the type is marshalled by reference.
If myType.IsMarshalByRef Then
myElementType = " marshalled by reference"
Return True
End If
Return False
End Function 'IsMarshalByRefImpl
End Class 'MyTypeDelegatorClass
Public Class MyTypeDemoClass
Public Shared Sub Main()
Try
Dim myType As MyTypeDelegatorClass
Console.WriteLine("Determine whether MyContextBoundClass is marshalled by reference.")
' Determine whether MyContextBoundClass is marshalled by reference.
myType = New MyTypeDelegatorClass(GetType(MyContextBoundClass))
If myType.IsMarshalByRef Then
Console.WriteLine(GetType(MyContextBoundClass).ToString() + " is marshalled by reference.")
Else
Console.WriteLine(GetType(MyContextBoundClass).ToString() + " is not marshalled by reference.")
End If
' Determine whether int is marshalled by reference.
myType = New MyTypeDelegatorClass(GetType(Integer))
Console.WriteLine(ControlChars.NewLine + "Determine whether int is marshalled by reference.")
If myType.IsMarshalByRef Then
Console.WriteLine(GetType(Integer).ToString() + " is marshalled by reference.")
Else
Console.WriteLine(GetType(Integer).ToString() + " is not marshalled by reference.")
End If
Catch e As Exception
Console.WriteLine("Exception: {0}", e.Message.ToString())
End Try
End Sub 'Main
End Class 'MyTypeDemoClass
' This class is used to demonstrate 'IsMarshalByRefImpl' method.
Public Class MyContextBoundClass
Inherits ContextBoundObject
Public myString As String = "This class is used to demonstrate members of the Type class."
End Class 'MyContextBoundClass
[C#]
using System;
using System.Reflection;
public class MyTypeDelegatorClass : TypeDelegator
{
public string myElementType = null;
private Type myType = null ;
public MyTypeDelegatorClass(Type myType) : base(myType)
{
this.myType = myType;
}
// Override IsMarshalByRefImpl.
protected override bool IsMarshalByRefImpl()
{
// Determine whether the type is marshalled by reference.
if(myType.IsMarshalByRef)
{
myElementType = " marshalled by reference";
return true;
}
return false;
}
}
public class MyTypeDemoClass
{
public static void Main()
{
try
{
MyTypeDelegatorClass myType;
Console.WriteLine ("Determine whether MyContextBoundClass is marshalled by reference.");
// Determine whether MyContextBoundClass type is marshalled by reference.
myType = new MyTypeDelegatorClass(typeof(MyContextBoundClass));
if( myType.IsMarshalByRef )
{
Console.WriteLine(typeof(MyContextBoundClass) + " is marshalled by reference.");
}
else
{
Console.WriteLine(typeof(MyContextBoundClass) + " is not marshalled by reference.");
}
// Determine whether int type is marshalled by reference.
myType = new MyTypeDelegatorClass(typeof(int));
Console.WriteLine ("\nDetermine whether int is marshalled by reference.");
if( myType.IsMarshalByRef)
{
Console.WriteLine(typeof(int) + " is marshalled by reference.");
}
else
{
Console.WriteLine(typeof(int) + " is not marshalled by reference.");
}
}
catch( Exception e )
{
Console.WriteLine("Exception: {0}", e.Message);
}
}
}
// This class is used to demonstrate the IsMarshalByRefImpl method.
public class MyContextBoundClass : ContextBoundObject
{
public string myString = "This class is used to demonstrate members of the Type class.";
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
public __gc class MyTypeDelegatorClass : public TypeDelegator {
public:
String* myElementType;
private:
Type* myType;
public:
MyTypeDelegatorClass(Type* myType) : TypeDelegator(myType) {
this->myType = myType;
}
// Override IsMarshalByRefImpl.
protected:
bool IsMarshalByRefImpl() {
// Determine whether the type is marshalled by reference.
if (myType->IsMarshalByRef) {
myElementType = S" marshalled by reference";
return true;
}
return false;
}
};
public __gc class MyTypeDemoClass {
};
// This class is used to demonstrate the IsMarshalByRefImpl method.
public __gc class MyContextBoundClass : public ContextBoundObject {
public:
String* myString;
};
int main() {
try {
MyTypeDelegatorClass* myType;
Console::WriteLine (S"Determine whether MyContextBoundClass is marshalled by reference.");
// Determine whether MyContextBoundClass type is marshalled by reference.
myType = new MyTypeDelegatorClass(__typeof(MyContextBoundClass));
if (myType->IsMarshalByRef) {
Console::WriteLine(S"{0} is marshalled by reference.", __typeof(MyContextBoundClass));
} else {
Console::WriteLine(S"{0} is not marshalled by reference.", __typeof(MyContextBoundClass));
}
// Determine whether int type is marshalled by reference.
myType = new MyTypeDelegatorClass(__typeof(int));
Console::WriteLine (S"\nDetermine whether int is marshalled by reference.");
if (myType->IsMarshalByRef) {
Console::WriteLine(S"{0} is marshalled by reference.", __typeof(int));
} else {
Console::WriteLine(S"{0} is not marshalled by reference.", __typeof(int));
}
} catch (Exception* e) {
Console::WriteLine(S"Exception: {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ