Merge pull request #3028 from lateralusX/jlorenss/threadpool_warning
[mono.git] / mcs / class / referencesource / mscorlib / system / runtime / interopservices / arraywithoffset.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 namespace System.Runtime.InteropServices {
7
8     using System;
9     using System.Runtime.CompilerServices;
10     using System.Runtime.Versioning;
11
12     [Serializable]
13     [System.Runtime.InteropServices.ComVisible(true)]
14     public struct ArrayWithOffset
15     {
16         //private ArrayWithOffset()
17         //{
18         //    throw new Exception();
19         //}
20     
21         [System.Security.SecuritySafeCritical]  // auto-generated
22         public ArrayWithOffset(Object array, int offset)
23         {
24             m_array  = array;
25             m_offset = offset;
26             m_count  = 0;
27             m_count  = CalculateCount();
28         }
29     
30         public Object GetArray()
31         {
32             return m_array;
33         }
34     
35         public int GetOffset()
36         {
37             return m_offset;
38         }
39     
40         public override int GetHashCode()
41         {
42             return m_count + m_offset;
43         }
44         
45         public override bool Equals(Object obj)
46         {
47             if (obj is ArrayWithOffset)
48                 return Equals((ArrayWithOffset)obj);
49             else
50                 return false;
51         }
52
53         public bool Equals(ArrayWithOffset obj)
54         {
55             return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
56         }
57     
58         public static bool operator ==(ArrayWithOffset a, ArrayWithOffset b)
59         {
60             return a.Equals(b);
61         }
62         
63         public static bool operator !=(ArrayWithOffset a, ArrayWithOffset b)
64         {
65             return !(a == b);
66         }
67
68 #if MONO
69         int CalculateCount()
70         {
71             Array a = m_array as Array;
72             if (a == null)
73                 throw new ArgumentException ();
74
75             var total = a.Rank * a.Length;
76             return total - m_offset;
77         }
78 #else
79         [System.Security.SecurityCritical]  // auto-generated
80         [ResourceExposure(ResourceScope.None)]
81         [MethodImplAttribute(MethodImplOptions.InternalCall)]
82         private extern int CalculateCount();
83 #endif
84     
85         private Object m_array;
86         private int    m_offset;
87         private int    m_count;
88     }
89
90 }