Export (0) Print
Expand All
Expand Minimize

Type::IsMarshalByRefImpl Method

Implements the IsMarshalByRef property and determines whether the Type is marshaled by reference.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

protected:
virtual bool IsMarshalByRefImpl()

Return Value

Type: System::Boolean
true if the Type is marshaled by reference; otherwise, false.

This method can be overridden by a derived class.

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 );
   }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft