System.Type.IsMarshalByRefImpl 方法

方法描述

实现 IsMarshalByRef 属性并确定 Type 是否按引用来进行封送。

语法定义(C# System.Type.IsMarshalByRefImpl 方法 的用法)

protected virtual bool IsMarshalByRefImpl()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 System.Boolean 如果 Type 是由引用封送的,则为 true;否则为 false。

提示和注释

此方法可由派生类重写。

System.Type.IsMarshalByRefImpl 方法例子

下面的示例确定是否按引用封送给定的类型,并显示结果。

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.";
}

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。