This documentation is archived and is not being maintained.

ObjRef.TypeInfo Property

Gets or sets the IRemotingTypeInfo for the object that the ObjRef describes.

[Visual Basic]
Public Overridable Property TypeInfo As IRemotingTypeInfo
[C#]
public virtual IRemotingTypeInfo TypeInfo {get; set;}
[C++]
public: __property virtual IRemotingTypeInfo* get_TypeInfo();
public: __property virtual void set_TypeInfo(IRemotingTypeInfo*);
[JScript]
public function get TypeInfo() : IRemotingTypeInfo;
public function set TypeInfo(IRemotingTypeInfo);

Property Value

The IRemotingTypeInfo for the object that the ObjRef describes.

Remarks

TypeInfo contains detailed information about the type of remote object represented by the current ObjRef. The current property contains a list of interfaces that the type implements, as well as the type hierarchy. This information might be used to refine the proxy incrementally to adjust to the client's view of the remote object's type.

Example

[C#] 
// a custom ObjRef class that outputs its status
public class MyObjRef : ObjRef {
   
   // only instantiate via marshaling or deserialization
   private MyObjRef() { }

   public MyObjRef(MarshalByRefObject o, Type t) : base(o, t) {
      Console.WriteLine("Created MyObjRef.");
      ORDump();
   }

   public MyObjRef(SerializationInfo i, StreamingContext c) : base(i, c) {
      Console.WriteLine("Deserialized MyObjRef.");
   }

   public override void GetObjectData(SerializationInfo s, StreamingContext c) {
      // After calling the base method, change the type from ObjRef to MyObjRef
      base.GetObjectData(s, c);
      s.SetType(GetType());
      Console.WriteLine("Serialized MyObjRef.");
   }

   public override Object GetRealObject(StreamingContext context) {

      if ( IsFromThisAppDomain() || IsFromThisProcess() )  {
         Console.WriteLine("Returning actual object referenced by MyObjRef.");
         return base.GetRealObject(context);
      }
      else {
         Console.WriteLine("Returning proxy to remote object.");
         return RemotingServices.Unmarshal(this);
      }
   }   

   public void ORDump() {

      Console.WriteLine(" --- Reporting MyObjRef Info --- ");
      Console.WriteLine("Reference to {0}.", TypeInfo.TypeName);
      Console.WriteLine("URI is {0}.", URI);

      Console.WriteLine("\nWriting EnvoyInfo: ");
      
      if ( EnvoyInfo != null) {

         IMessageSink EISinks = EnvoyInfo.EnvoySinks;

         while (EISinks != null) {
            Console.WriteLine("\tSink: " + EISinks.ToString());  
            EISinks = EISinks.NextSink;
         }
      }
      else
         Console.WriteLine("\t {no sinks}");

      Console.WriteLine("\nWriting ChannelInfo: ");
      for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
         Console.WriteLine ("\tChannel: {0}", ChannelInfo.ChannelData[i]);
      
      Console.WriteLine(" ----------------------------- ");
   }
}

// a class that uses MyObjRef
public class LocalObject : MarshalByRefObject  {

   // overriding CreateObjRef will allow us to return a custom ObjRef
   public override ObjRef CreateObjRef(Type t) {

      return new MyObjRef(this, t);
   }
}

[C++] 
// a custom ObjRef class that outputs its status
public __gc class MyObjRef : public ObjRef 
{
    // only instantiate via marshaling or deserialization
private:
    MyObjRef() { }

public:
    MyObjRef(MarshalByRefObject* o, Type* t) : ObjRef(o, t) 
    {
        Console::WriteLine(S"Created MyObjRef.");
        ORDump();
    }

public:
    MyObjRef(SerializationInfo* i, StreamingContext c) : ObjRef(i, c) 
    {
        Console::WriteLine(S"Deserialized MyObjRef.");
    }

public:
    void GetObjectData(SerializationInfo* s, StreamingContext c) 
    {
        // After calling the base method, change the type from ObjRef to MyObjRef
        ObjRef::GetObjectData(s, c);
        s->SetType(GetType());
        Console::WriteLine(S"Serialized MyObjRef.");
    }

public:
    Object* GetRealObject(StreamingContext context) 
    {
        if (IsFromThisAppDomain() || IsFromThisProcess()) 
        {
            Console::WriteLine(S"Returning actual Object* referenced by MyObjRef.");
            return ObjRef::GetRealObject(context);
        }
        else 
        {
            Console::WriteLine(S"Returning proxy to remote Object*.");
            return RemotingServices::Unmarshal(this);
        }
    }   

public:
    void ORDump() 
    {
        Console::WriteLine(S" --- Reporting MyObjRef Info --- ");
        Console::WriteLine(S"Reference to {0}.", TypeInfo->TypeName);
        Console::WriteLine(S"URI is {0}.", URI);

        Console::WriteLine(S"\nWriting EnvoyInfo: ");

        if (EnvoyInfo != 0) 
        {
            IMessageSink* EISinks = EnvoyInfo->EnvoySinks;

            while (EISinks != 0) 
            {
                Console::WriteLine(S"\tSink: {0}", EISinks);  
                EISinks = EISinks->NextSink;
            }
        } 
        else
            Console::WriteLine(S"\t {no sinks}");

        Console::WriteLine(S"\nWriting ChannelInfo: ");
        for (int i = 0; i < ChannelInfo->ChannelData->Length; i++)
            Console::WriteLine (S"\tChannel: {0}", ChannelInfo->ChannelData->Item[i]);

        Console::WriteLine(S" ----------------------------- ");
    }
};

// a class that uses MyObjRef
public __gc class LocalObject : public MarshalByRefObject 
{
    // overriding CreateObjRef will allow us to return a custom ObjRef
public:
    ObjRef* CreateObjRef(Type* t) 
    {
        return new MyObjRef(this, t);
    }
};

[Visual Basic, JScript] No example is available for Visual Basic or JScript. To view a C# or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ObjRef Class | ObjRef Members | System.Runtime.Remoting Namespace

Show: