ObjRef.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // System.Runtime.Remoting.ObjRef.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Dietmar Maurer ([email protected])
  7. // Lluis Sanchez Gual ([email protected])
  8. //
  9. // (C) Ximian, Inc. http://www.ximian.com
  10. //
  11. //
  12. // FIXME: This is just a skeleton for practical purposes.
  13. //
  14. using System;
  15. using System.Runtime.Serialization;
  16. using System.Runtime.Remoting.Channels;
  17. using System.Runtime.Remoting.Messaging;
  18. using System.Runtime.Remoting.Proxies;
  19. namespace System.Runtime.Remoting {
  20. [Serializable]
  21. public class ObjRef : IObjectReference, ISerializable
  22. {
  23. IChannelInfo channel_info;
  24. string uri;
  25. Type type;
  26. public ObjRef ()
  27. {
  28. // no idea why this needs to be public
  29. }
  30. public ObjRef (MarshalByRefObject mbr, Type type)
  31. {
  32. if (mbr == null)
  33. throw new ArgumentNullException ("mbr");
  34. if (type == null)
  35. throw new ArgumentNullException ("type");
  36. // The ObjRef can only be constructed if the given mbr
  37. // has already been marshalled using RemotingServices.Marshall
  38. this.uri = RemotingServices.GetObjectUri(mbr);
  39. this.type = type;
  40. channel_info = new ChannelInfoStore ();
  41. }
  42. protected ObjRef (SerializationInfo si, StreamingContext sc)
  43. {
  44. SerializationInfoEnumerator en = si.GetEnumerator();
  45. while (en.MoveNext ()) {
  46. switch (en.Name) {
  47. case "uri":
  48. uri = (string)en.Value;
  49. break;
  50. case "type":
  51. type = (Type)en.Value;
  52. break;
  53. case "channelInfo":
  54. type = (Type)en.Value;
  55. break;
  56. default:
  57. throw new NotSupportedException ();
  58. }
  59. }
  60. }
  61. public virtual IChannelInfo ChannelInfo {
  62. get {
  63. return channel_info;
  64. }
  65. set {
  66. channel_info = value;
  67. }
  68. }
  69. [MonoTODO]
  70. public virtual IEnvoyInfo EnvoyInfo {
  71. get {
  72. throw new NotImplementedException ();
  73. }
  74. set {
  75. throw new NotImplementedException ();
  76. }
  77. }
  78. [MonoTODO]
  79. public virtual IRemotingTypeInfo TypeInfo {
  80. get {
  81. throw new NotImplementedException ();
  82. }
  83. set {
  84. throw new NotImplementedException ();
  85. }
  86. }
  87. public virtual string URI {
  88. get {
  89. return uri;
  90. }
  91. set {
  92. uri = value;
  93. }
  94. }
  95. public virtual void GetObjectData (SerializationInfo si, StreamingContext sc)
  96. {
  97. si.SetType (type);
  98. si.AddValue ("url", uri);
  99. si.AddValue ("type", type, typeof (Type));
  100. si.AddValue ("channelInfo", channel_info, typeof(IChannelInfo));
  101. }
  102. public virtual object GetRealObject (StreamingContext sc)
  103. {
  104. return RemotingServices.GetRemoteObject(type, null, channel_info.ChannelData);
  105. }
  106. public bool IsFromThisAppDomain ()
  107. {
  108. Identity identity = RemotingServices.GetIdentityForUri (uri);
  109. if (identity == null) return false; // URI not registered in this domain
  110. return identity.IsFromThisAppDomain;
  111. }
  112. [MonoTODO]
  113. public bool IsFromThisProcess ()
  114. {
  115. // as yet we do not consider this optimization
  116. return false;
  117. }
  118. }
  119. }