Type.IsMarshalByRefImpl Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Implements the IsMarshalByRef property and determines whether the Type is marshaled by reference.
protected:
virtual bool IsMarshalByRefImpl();
protected virtual bool IsMarshalByRefImpl ();
abstract member IsMarshalByRefImpl : unit -> bool
override this.IsMarshalByRefImpl : unit -> bool
Protected Overridable Function IsMarshalByRefImpl () As Boolean
Returns
true
if the Type is marshaled by reference; otherwise, false
.
Examples
The following example determines whether the given type is marshaled by reference and displays the result.
using namespace System;
using namespace System::Reflection;
public ref class MyTypeDelegatorClass: public TypeDelegator
{
public:
String^ myElementType;
private:
Type^ myType;
public:
MyTypeDelegatorClass( Type^ myType )
: TypeDelegator( myType )
{
this->myType = myType;
}
protected:
// Override IsMarshalByRefImpl.
virtual bool IsMarshalByRefImpl() override
{
// Determine whether the type is marshalled by reference.
if ( myType->IsMarshalByRef )
{
myElementType = " marshalled by reference";
return true;
}
return false;
}
};
public ref class MyTypeDemoClass{};
// This class is used to demonstrate the IsMarshalByRefImpl method.
public ref class MyContextBoundClass: public ContextBoundObject
{
public:
String^ myString;
};
int main()
{
try
{
MyTypeDelegatorClass^ myType;
Console::WriteLine( "Determine whether MyContextBoundClass is marshalled by reference." );
// Determine whether MyContextBoundClass type is marshalled by reference.
myType = gcnew MyTypeDelegatorClass( MyContextBoundClass::typeid );
if ( myType->IsMarshalByRef )
{
Console::WriteLine( "{0} is marshalled by reference.", MyContextBoundClass::typeid );
}
else
{
Console::WriteLine( "{0} is not marshalled by reference.", MyContextBoundClass::typeid );
}
// Determine whether int type is marshalled by reference.
myType = gcnew MyTypeDelegatorClass( int::typeid );
Console::WriteLine( "\nDetermine whether int is marshalled by reference." );
if ( myType->IsMarshalByRef )
{
Console::WriteLine( "{0} is marshalled by reference.", int::typeid );
}
else
{
Console::WriteLine( "{0} is not marshalled by reference.", int::typeid );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
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.";
}
open System
open System.Reflection
// This class is used to demonstrate the IsMarshalByRefImpl method.
type MyContextBoundClass() =
inherit ContextBoundObject()
let myString = "This class is used to demonstrate members of the Type class."
type MyTypeDelegatorClass(myType) =
inherit TypeDelegator(myType)
[<DefaultValue>]
val mutable public myElementType : string
// Override IsMarshalByRefImpl.
override this.IsMarshalByRefImpl() =
// Determine whether the type is marshalled by reference.
if myType.IsMarshalByRef then
this.myElementType <- " marshalled by reference"
true
else false
try
printfn "Determine whether MyContextBoundClass is marshalled by reference."
// Determine whether MyContextBoundClass type is marshalled by reference.
let myType = MyTypeDelegatorClass typeof<MyContextBoundClass>
if myType.IsMarshalByRef then
printfn $"{typeof<MyContextBoundClass>} is marshalled by reference."
else
printfn $"{typeof<MyContextBoundClass>} is not marshalled by reference."
// Determine whether int type is marshalled by reference.
let myType = MyTypeDelegatorClass typeof<int>
printfn "\nDetermine whether int is marshalled by reference."
if myType.IsMarshalByRef then
printfn $"{typeof<int>} is marshalled by reference."
else
printfn $"{typeof<int>} is not marshalled by reference."
with e ->
printfn $"Exception: {e.Message}"
Imports System.Reflection
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
' 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
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
End Class
' 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
Remarks
This method can be overridden by a derived class.
Applies to
See also
Dolgozzon együtt velünk a GitHubon
A tartalom forrása a GitHubon található, ahol létrehozhat és áttekinthet problémákat és lekéréses kérelmeket is. További információért tekintse meg a közreműködői útmutatónkat.