2002-03-06 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / System / Delegate.cs
1 //
2 // System.Delegate.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9 // TODO:  Mucho left to implement
10 //
11
12 using System;
13 using System.Globalization;
14 using System.Runtime.Serialization;
15
16 namespace System {
17
18         [MonoTODO]
19         public abstract class Delegate : ICloneable, ISerializable {
20                 protected Type target_type;
21                 protected object m_target;
22                 protected string method;
23                 protected IntPtr method_ptr;
24
25                 protected Delegate (object target, string method)
26                 {
27                         if (target == null)
28                                 throw new ArgumentNullException (Locale.GetText ("Target object is null"));
29
30                         if (method == null)
31                                 throw new ArgumentNullException (Locale.GetText ("method name is null"));
32
33                         this.target_type = null;
34                         this.method_ptr = IntPtr.Zero;
35                         this.m_target = target;
36                         this.method = method;
37                 }
38
39                 protected Delegate (Type target_type, string method)
40                 {
41                         if (m_target == null)
42                                 throw new ArgumentNullException (Locale.GetText ("Target type is null"));
43
44                         if (method == null)
45                                 throw new ArgumentNullException (Locale.GetText ("method string is null"));
46
47                         this.target_type = target_type;
48                         this.method_ptr = IntPtr.Zero;
49                         this.m_target = null;
50                         this.method = method;
51                 }
52
53 #if NOTYET
54                 public MethodInfo Method {
55                         get {
56                                 return null;
57                         }
58                 }
59 #endif
60
61                 public object Target {
62                         get {
63                                 return m_target;
64                         }
65                 }
66
67
68                 //
69                 // Methods
70                 //
71
72                 public abstract object Clone ();
73
74                 public override bool Equals (object o)
75                 {
76                         if (!(o is System.Delegate))
77                                 return false;
78
79                         Delegate d = (Delegate) o;
80                         
81                         if ((d.target_type == target_type) &&
82                             (d.m_target == m_target) &&
83                             (d.method == method))
84                                 return true;
85
86                         return false;
87                 }
88
89                 public override int GetHashCode ()
90                 {
91                         return method.GetHashCode ();
92                 }
93
94                 // This is from ISerializable
95                 [MonoTODO]
96                 public void GetObjectData (SerializationInfo info, StreamingContext context)
97                 {
98                         // TODO: IMPLEMENT ME
99                 }
100
101                 public static Delegate Combine (Delegate a, Delegate b)
102                 {
103                         if (a == null){
104                                 if (b == null)
105                                         return null;
106                                 return b;
107                         } else 
108                                 if (b == null)
109                                         return a;
110
111                         if (a.GetType () != b.GetType ())
112                                 throw new ArgumentException (Locale.GetText ("Incompatible Delegate Types"));
113                         
114                         return a.CombineImpl (b);
115                 }
116
117                 protected virtual Delegate CombineImpl (Delegate d)
118                 {
119                         throw new MulticastNotSupportedException ("");
120                 }
121
122                 [MonoTODO]
123                 public static Delegate Remove( Delegate source, Delegate value) {
124                         throw new NotImplementedException ();
125                 }
126         }
127 }