Type.IsMarshalByRef 属性

获取一个值,该值指示 Type 是否按引用进行封送。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public ReadOnly Property IsMarshalByRef As Boolean
用法
Dim instance As Type
Dim value As Boolean

value = instance.IsMarshalByRef
public bool IsMarshalByRef { get; }
public:
virtual property bool IsMarshalByRef {
    bool get () sealed;
}
/** @property */
public final boolean get_IsMarshalByRef ()
public final function get IsMarshalByRef () : boolean

属性值

如果 Type 是由引用封送的,则为 true;否则为 false

示例

下面的示例演示 Type 类的 IsContextfulIsMarshalByRefIsPrimitive 属性。它将检查给定类型可否在上下文中承载,该类型可否按引用来进行封送,以及该类型是否是基元数据类型。

Imports System
Imports System.Runtime.Remoting.Contexts
Imports Microsoft.VisualBasic
Public Class MyContextBoundClass
    Inherits ContextBoundObject
    Public myString As String = "This class demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties."
End Class 'MyContextBoundClass
Public Class MyTypeDemoClass
    Public Shared Sub Main()
        Try
            ' Determine whether the types can be hosted in a Context.
            Console.WriteLine("The Contextful property for the {0} type is {1}.", GetType(MyTypeDemoClass).Name, GetType(MyTypeDemoClass).IsContextful.ToString())
            Console.WriteLine("The Contextful property for the {0} type is {1}.", GetType(MyContextBoundClass).Name, GetType(MyContextBoundClass).IsContextful.ToString())
            ' Determine whether the types are marshalled by reference.
            Console.WriteLine("The MarshalByRef property of {0} is {1}.", GetType(MyTypeDemoClass).Name, GetType(MyTypeDemoClass).IsMarshalByRef.ToString())
            Console.WriteLine("The MarshalByRef property of {0} is {1}.", GetType(MyContextBoundClass).Name, GetType(MyContextBoundClass).IsMarshalByRef.ToString())
            ' Determine whether the types are primitive datatypes.
            Console.WriteLine("Is {0} a primitive data type? {1}.", GetType(Integer).Name, GetType(Integer).IsPrimitive.ToString())
            Console.WriteLine("Is {0} a primitive data type? {1}.", GetType(String).Name, GetType(String).IsPrimitive.ToString())
        Catch e As Exception
            Console.WriteLine("An exception occurred: " + e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'MyTypeDemoClass
using System;
using System.Runtime.Remoting.Contexts;
public class MyContextBoundClass: ContextBoundObject
{
    public string myString = "This class demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties.";
}
public class MyTypeDemoClass
{
    public static void Main()
    {
        try
        {
            // Determine whether the types can be hosted in a Context.
            Console.WriteLine ("The IsContextful property for the {0} type is {1}.", typeof(MyTypeDemoClass).Name, typeof(MyTypeDemoClass).IsContextful);
            Console.WriteLine ("The IsContextful property for the {0} type is {1}.", typeof(MyContextBoundClass).Name, typeof(MyContextBoundClass).IsContextful);

            // Determine whether the types are marshalled by reference.
            Console.WriteLine ("The MarshalByRef property of {0} is {1}.", typeof(MyTypeDemoClass).Name, typeof(MyTypeDemoClass).IsMarshalByRef);
            Console.WriteLine ("The MarshalByRef property of {0} is {1}.", typeof(MyContextBoundClass).Name, typeof(MyContextBoundClass).IsMarshalByRef);
            
            // Determine whether the types are primitive datatypes.
            Console.WriteLine ("Is {0} is a primitive data type? {1}.", typeof(int).Name, typeof(int).IsPrimitive);
            Console.WriteLine ("Is {0} a primitive data type? {1}.", typeof(string).Name, typeof(string).IsPrimitive);
        } 
        catch (Exception e)
        {
            Console.WriteLine("An exception occurred: " + e.Message);
        }
    }
}
using namespace System;
using namespace System::Runtime::Remoting::Contexts;
public ref class MyContextBoundClass: public ContextBoundObject
{
public:
   String^ myString;
};

public ref class MyTypeDemoClass
{
public:
   void Demo()
   {
      try
      {
         // Determine whether the types can be hosted in a Context.
         Console::WriteLine( "The IsContextful property for the {0} type is {1}.", MyTypeDemoClass::typeid->Name, MyTypeDemoClass::typeid->IsContextful );
         Console::WriteLine( "The IsContextful property for the {0} type is {1}.", MyContextBoundClass::typeid->Name, MyContextBoundClass::typeid->IsContextful );
         
         // Determine whether the types are marshalled by reference.
         Console::WriteLine( "The MarshalByRef property of {0} is {1}.", MyTypeDemoClass::typeid->Name, MyTypeDemoClass::typeid->IsMarshalByRef );
         Console::WriteLine( "The MarshalByRef property of {0} is {1}.", MyContextBoundClass::typeid->Name, MyContextBoundClass::typeid->IsMarshalByRef );
         
         // Determine whether the types are primitive datatypes.
         Console::WriteLine( "Is {0} is a primitive data type? {1}.", int::typeid->Name, int::typeid->IsPrimitive );
         Console::WriteLine( "Is {0} a primitive data type? {1}.", String::typeid->Name, String::typeid->IsPrimitive );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "An exception occurred: {0}", e->Message );
      }
   }
};

int main()
{
   MyTypeDemoClass^ mtdc = gcnew MyTypeDemoClass;
   mtdc->Demo();
}
import System.*;
import System.Runtime.Remoting.Contexts.*;

public class MyContextBoundClass extends ContextBoundObject
{
    public String myString = "This class demonstrates the IsContextful, "
        +"IsMarshalByRef, and IsPrimitive properties.";
} //MyContextBoundClass

public class MyTypeDemoClass
{
    public static void main(String[] args)
    {
        try {
            // Determine whether the types can be hosted in a Context.
            Console.WriteLine("The IsContextful property for the"
                +" {0} type is {1}.", MyTypeDemoClass.class.ToType().get_Name(),
                System.Convert.ToString(MyTypeDemoClass.class.ToType().
                get_IsContextful()));
            Console.WriteLine("The IsContextful property for the"
                +" {0} type is {1}.", MyContextBoundClass.class.ToType().
                get_Name(), System.Convert.ToString(MyContextBoundClass.class.
                ToType().get_IsContextful()));

            // Determine whether the types are marshalled by reference.
            Console.WriteLine("The MarshalByRef property of {0} is {1}.",
                MyTypeDemoClass.class.ToType().get_Name(),
                System.Convert.ToString(MyTypeDemoClass.class.ToType().
                get_IsMarshalByRef()));
            Console.WriteLine("The MarshalByRef property of {0} is {1}.",
                MyContextBoundClass.class.ToType().get_Name(),
                System.Convert.ToString(MyContextBoundClass.class.ToType().
                get_IsMarshalByRef()));

            // Determine whether the types are primitive datatypes.
            Console.WriteLine("Is {0} is a primitive data type? {1}.",
                int.class.ToType().get_Name(),
                System.Convert.ToString(int.class.ToType().get_IsPrimitive()));
            Console.WriteLine("Is {0} a primitive data type? {1}.",
                String.class.ToType().get_Name(),System.Convert.ToString(
                String.class.ToType().get_IsPrimitive()));
        }
        catch (System.Exception e) {
            Console.WriteLine("An exception occurred: " + e.get_Message());
        }
    } //main
} //MyTypeDemoClass

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、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

请参见

参考

Type 类
Type 成员
System 命名空间
IsMarshalByRefImpl