Added Mono.Tasklets test
[mono.git] / mcs / class / corlib / Mono / RuntimeHandles.cs
1 //
2 // Wrapper handles for Mono Runtime internal structs
3 //
4 // Authors:
5 //   Aleksey Kliger <aleksey@xamarin.com>
6 //   Rodrigo Kumpera <kumpera@xamarin.com>
7 //
8 // Copyright 2016 Dot net foundation.
9 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
10 //
11
12 using System;
13 using System.Runtime.CompilerServices;
14
15 namespace Mono {
16
17         internal struct RuntimeClassHandle {
18                 unsafe RuntimeStructs.MonoClass* value;
19
20                 internal unsafe RuntimeClassHandle (RuntimeStructs.MonoClass* value) {
21                         this.value = value;
22                 }
23
24                 internal unsafe RuntimeClassHandle (IntPtr ptr) {
25                         this.value = (RuntimeStructs.MonoClass*) ptr;
26                 }
27
28                 internal unsafe RuntimeStructs.MonoClass* Value {
29                         get { return value; }
30                 }
31
32                 public override bool Equals (object obj)
33                 {
34                         if (obj == null || GetType () != obj.GetType ())
35                                 return false;
36
37                         unsafe { return value == ((RuntimeClassHandle)obj).Value; }
38                 }
39
40                 public override int GetHashCode ()
41                 {
42                         unsafe { return ((IntPtr)value).GetHashCode (); }
43                 }
44
45                 public bool Equals (RuntimeClassHandle handle)
46                 {
47                         unsafe { return value == handle.Value; }
48                 }
49
50                 public static bool operator == (RuntimeClassHandle left, Object right)
51                 {
52                         return (right != null) && (right is RuntimeClassHandle) && left.Equals ((RuntimeClassHandle)right);
53                 }
54
55                 public static bool operator != (RuntimeClassHandle left, Object right)
56                 {
57                         return (right == null) || !(right is RuntimeClassHandle) || !left.Equals ((RuntimeClassHandle)right);
58                 }
59
60                 public static bool operator == (Object left, RuntimeClassHandle right)
61                 {
62                         return (left != null) && (left is RuntimeClassHandle) && ((RuntimeClassHandle)left).Equals (right);
63                 }
64
65                 public static bool operator != (Object left, RuntimeClassHandle right)
66                 {
67                         return (left == null) || !(left is RuntimeClassHandle) || !((RuntimeClassHandle)left).Equals (right);
68                 }
69
70                 [MethodImpl(MethodImplOptions.InternalCall)]
71                 internal unsafe extern static IntPtr GetTypeFromClass (RuntimeStructs.MonoClass *klass);
72
73                 internal RuntimeTypeHandle GetTypeHandle ()
74                 {
75                         unsafe { return new RuntimeTypeHandle (GetTypeFromClass (value)); }
76                 }
77         }
78
79         internal struct RuntimeRemoteClassHandle {
80                 unsafe RuntimeStructs.RemoteClass* value;
81
82                 internal unsafe RuntimeRemoteClassHandle (RuntimeStructs.RemoteClass* value)
83                 {
84                         this.value = value;
85                 }
86
87                 internal RuntimeClassHandle ProxyClass {
88                         get {
89                                 unsafe {
90                                         return new RuntimeClassHandle (value->proxy_class);
91                                 }
92                         }
93                 }
94         }
95 }