2005-11-24 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / corlib / System.Runtime.CompilerServices / RuntimeHelpers.cs
1 // System.Runtime.CompilerServices.RuntimeHelpers
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 // Paolo Molaro (lupus@ximian.com)
5 //
6 // (C) Ximian, Inc. 2001
7
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using System.Runtime.ConstrainedExecution;
33 #endif
34
35 namespace System.Runtime.CompilerServices
36 {
37 #if NET_2_0
38         public static class RuntimeHelpers
39 #else
40         [Serializable]
41         public sealed class RuntimeHelpers
42 #endif
43         {
44 #if NET_2_0
45                 public delegate void TryCode (Object userData);
46
47                 public delegate void CleanupCode (Object userData, bool exceptionThrown);
48 #endif
49
50 #if !NET_2_0
51                 private RuntimeHelpers () {}
52 #endif
53
54                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
55                 static extern void InitializeArray (Array array, IntPtr fldHandle);
56
57                 public static void InitializeArray (Array array, RuntimeFieldHandle fldHandle)
58                 {
59                         InitializeArray (array, fldHandle.Value);
60                 }
61
62                 public static extern int OffsetToStringData {
63                         [MethodImpl (MethodImplOptions.InternalCall)]
64                         get;
65                 }
66
67 #if NET_1_1
68                 public static int GetHashCode (object o) {
69                         return Object.InternalGetHashCode (o);
70                 }
71
72                 public static new bool Equals (object o1, object o2) {
73                         // LAMESPEC: According to MSDN, this is equivalent to 
74                         // Object::Equals (). But the MS version of Object::Equals()
75                         // includes the functionality of ValueType::Equals(), while
76                         // our version does not.
77                         if (o1 == o2)
78                                 return true;
79                         if ((o1 == null) || (o2 == null))
80                                 return false;
81                         if (o1 is ValueType)
82                                 return ValueType.DefaultEquals (o1, o2);
83                         else
84                                 return Object.Equals (o1, o2);
85                 }
86 #endif
87
88                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
89                 public static extern object GetObjectValue (object obj);
90
91                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
92                 static extern void RunClassConstructor (IntPtr type);
93
94                 public static void RunClassConstructor (RuntimeTypeHandle type)
95                 {
96                         RunClassConstructor (type.Value);
97                 }
98
99 #if NET_2_0
100                 [MonoTODO]
101                 public static void ExecuteCodeWithGuaranteedCleanup (TryCode code, CleanupCode backoutCode, Object userData) {
102                         throw new NotImplementedException ();
103                 }
104
105                 [MonoTODO]
106                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
107                 public static void PrepareConstrainedRegions () {
108                         throw new NotImplementedException ();
109                 }
110
111                 [MonoTODO]
112                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
113                 public static void PrepareConstrainedRegionsNoOP () {
114                         throw new NotImplementedException ();
115                 }
116
117                 [MonoTODO]
118                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
119                 public static void ProbeForSufficientStack() {
120                         throw new NotImplementedException ();
121                 }
122
123                 [MonoTODO]
124                 public static void PrepareDelegate (Delegate d) {
125                         if (d == null)
126                                 throw new ArgumentNullException ("d");
127                         throw new NotImplementedException ();
128                 }
129
130                 [MonoTODO]
131                 public static void PrepareMethod (RuntimeMethodHandle method) {
132                         throw new NotImplementedException ();
133                 }
134
135                 [MonoTODO]
136                 public static void PrepareMethod (RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation) {
137                         throw new NotImplementedException ();
138                 }
139
140                 [MonoTODO]
141                 public static void RunModuleConstructor (ModuleHandle module) {
142                         throw new NotImplementedException ();
143                 }
144 #endif
145         }
146 }