Identity.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // System.Runtime.Remoting.Identity.cs
  3. //
  4. // Author: Lluis Sanchez Gual ([email protected])
  5. //
  6. // (C) 2002, Lluis Sanchez Gual
  7. //
  8. using System.Runtime.Remoting.Messaging;
  9. using System.Runtime.Remoting.Proxies;
  10. using System.Runtime.Remoting.Contexts;
  11. namespace System.Runtime.Remoting
  12. {
  13. internal class Identity
  14. {
  15. // An Identity object holds remoting information about
  16. // an object. It can be used to store client side information
  17. // (information about how to reach the remote server),
  18. // and also to store server side information (information
  19. // about how to dispatch messages to the object in the server).
  20. // The object that this identity represents. Can be a MarshalByRefObject
  21. // (if it is a server object) or a transparent proxy (if it is a client
  22. // proxy to a remote object).
  23. object _realObject;
  24. Type _objectType;
  25. // URI of the object
  26. string _objectUri;
  27. // Message sink to use to send a message to the remote server
  28. IMessageSink _clientSink = null;
  29. // Message sink used in the server to dispatch a message
  30. // to the server object
  31. IMessageSink _serverSink = null;
  32. Context _context;
  33. ObjRef _objRef = null;
  34. public Identity(string objectUri, Context context, Type objectType)
  35. {
  36. _objectUri = objectUri;
  37. _context = context;
  38. _objectType = objectType;
  39. }
  40. public ObjRef CreateObjRef (Type requestedType)
  41. {
  42. // fixme: handle requested_type
  43. if (requestedType == null) requestedType = _objectType;
  44. ObjRef res = new ObjRef ((MarshalByRefObject)_realObject, requestedType);
  45. res.URI = _objectUri;
  46. _objRef = res;
  47. return res;
  48. }
  49. public bool IsFromThisAppDomain
  50. {
  51. get
  52. {
  53. // fixme: what if it is contextbound?
  54. return (_clientSink == null);
  55. }
  56. }
  57. public object RealObject
  58. {
  59. get { return _realObject; }
  60. set { _realObject = value; }
  61. }
  62. public string ObjectUri
  63. {
  64. get { return _objectUri; }
  65. }
  66. public IMessageSink ClientSink
  67. {
  68. get { return _clientSink; }
  69. set { _clientSink = value; }
  70. }
  71. public IMessageSink ServerSink
  72. {
  73. get
  74. {
  75. if (_serverSink == null) {
  76. _serverSink = _context.CreateServerObjectSinkChain((MarshalByRefObject)_realObject);
  77. }
  78. return _serverSink;
  79. }
  80. }
  81. public Context Context
  82. {
  83. get { return _context; }
  84. }
  85. }
  86. }