2 Copyright (C) 2008-2011 Jeroen Frijters
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
25 using System.Collections.Generic;
26 using System.Runtime.Serialization;
28 namespace IKVM.Reflection
30 public interface ICustomAttributeProvider
32 bool IsDefined(Type attributeType, bool inherit);
33 IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit);
37 public sealed class FileFormatLimitationExceededException : InvalidOperationException
39 public const int META_E_STRINGSPACE_FULL = unchecked((int)0x80131198);
41 public FileFormatLimitationExceededException(string message, int hresult)
44 this.HResult = hresult;
47 private FileFormatLimitationExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
54 get { return this.HResult; }
59 public sealed class Missing : ISerializable
61 public static readonly Missing Value = new Missing();
65 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
67 info.SetType(typeof(SingletonSerializationHelper));
71 private sealed class SingletonSerializationHelper : IObjectReference
73 public object GetRealObject(StreamingContext context)
82 internal static readonly T[] Array = new T[0];
87 internal static int[] Copy(int[] array)
89 if (array == null || array.Length == 0)
91 return Empty<int>.Array;
93 int[] copy = new int[array.Length];
94 Array.Copy(array, copy, array.Length);
98 internal static Type[] Copy(Type[] array)
100 if (array == null || array.Length == 0)
102 return Type.EmptyTypes;
104 Type[] copy = new Type[array.Length];
105 Array.Copy(array, copy, array.Length);
109 internal static T[] ToArray<T, V>(List<V> list, T[] empty) where V : T
111 if (list == null || list.Count == 0)
115 T[] array = new T[list.Count];
116 for (int i = 0; i < array.Length; i++)
123 internal static T[] ToArray<T>(IEnumerable<T> values)
125 return values == null
127 : new List<T>(values).ToArray();
130 // note that an empty array matches a null reference
131 internal static bool ArrayEquals(Type[] t1, Type[] t2)
139 return t2.Length == 0;
143 return t1.Length == 0;
145 if (t1.Length == t2.Length)
147 for (int i = 0; i < t1.Length; i++)
149 if (!TypeEquals(t1[i], t2[i]))
159 internal static bool TypeEquals(Type t1, Type t2)
169 return t1.Equals(t2);
172 internal static int GetHashCode(Type[] types)
179 foreach (Type t in types)
184 h ^= t.GetHashCode();
190 internal static bool ArrayEquals(CustomModifiers[] m1, CustomModifiers[] m2)
192 if (m1 == null || m2 == null)
196 if (m1.Length != m2.Length)
200 for (int i = 0; i < m1.Length; i++)
202 if (!m1[i].Equals(m2[i]))
210 internal static int GetHashCode(CustomModifiers[] mods)
215 foreach (CustomModifiers mod in mods)
217 h ^= mod.GetHashCode();
223 internal static T NullSafeElementAt<T>(T[] array, int index)
225 return array == null ? default(T) : array[index];
228 internal static int NullSafeLength<T>(T[] array)
230 return array == null ? 0 : array.Length;
234 [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)]
235 struct SingleConverter
237 [System.Runtime.InteropServices.FieldOffset(0)]
239 [System.Runtime.InteropServices.FieldOffset(0)]
242 internal static int SingleToInt32Bits(float v)
244 SingleConverter c = new SingleConverter();
249 internal static float Int32BitsToSingle(int v)
251 SingleConverter c = new SingleConverter();