[corlib] Improve file:// url handling in AppDomainSetup. (#16161)
[mono-project.git] / mcs / class / corlib / System / RuntimeFieldHandle.cs
blob40a467ffb22814f01fb39e4ee215877ba59cab5e
1 //
2 // System.RuntimeFieldHandle.cs
3 //
4 // Author:
5 // Miguel de Icaza (miguel@ximian.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Ximian, Inc. http://www.ximian.com
9 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Reflection;
35 using System.Runtime.Serialization;
36 using System.Runtime.InteropServices;
37 using System.Runtime.ConstrainedExecution;
38 using System.Runtime.CompilerServices;
40 namespace System
42 [ComVisible (true)]
43 [Serializable]
44 public struct RuntimeFieldHandle : ISerializable
46 IntPtr value;
48 internal RuntimeFieldHandle (IntPtr v)
50 value = v;
53 RuntimeFieldHandle (SerializationInfo info, StreamingContext context)
55 if (info == null)
56 throw new ArgumentNullException ("info");
58 RuntimeFieldInfo mf = ((RuntimeFieldInfo) info.GetValue ("FieldObj", typeof (RuntimeFieldInfo)));
59 value = mf.FieldHandle.Value;
60 if (value == IntPtr.Zero)
61 throw new SerializationException ("Insufficient state.");
64 public IntPtr Value {
65 get {
66 return value;
70 internal bool IsNullHandle ()
72 return value == IntPtr.Zero;
75 public void GetObjectData (SerializationInfo info, StreamingContext context)
77 if (info == null)
78 throw new ArgumentNullException ("info");
80 if (value == IntPtr.Zero)
81 throw new SerializationException ("Object fields may not be properly initialized");
83 info.AddValue ("FieldObj", (RuntimeFieldInfo) FieldInfo.GetFieldFromHandle (this), typeof (RuntimeFieldInfo));
86 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
87 public override bool Equals (object obj)
89 if (obj == null || GetType () != obj.GetType ())
90 return false;
92 return value == ((RuntimeFieldHandle)obj).Value;
95 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
96 public bool Equals (RuntimeFieldHandle handle)
98 return value == handle.Value;
101 public override int GetHashCode ()
103 return value.GetHashCode ();
106 public static bool operator == (RuntimeFieldHandle left, RuntimeFieldHandle right)
108 return left.Equals (right);
111 public static bool operator != (RuntimeFieldHandle left, RuntimeFieldHandle right)
113 return !left.Equals (right);
116 [MethodImplAttribute(MethodImplOptions.InternalCall)]
117 static extern void SetValueInternal (FieldInfo fi, object obj, object value);
119 internal static void SetValue (RuntimeFieldInfo field, Object obj, Object value, RuntimeType fieldType, FieldAttributes fieldAttr, RuntimeType declaringType, ref bool domainInitialized)
121 SetValueInternal (field, obj, value);
124 [MethodImplAttribute(MethodImplOptions.InternalCall)]
125 static unsafe extern internal Object GetValueDirect (RuntimeFieldInfo field, RuntimeType fieldType, void *pTypedRef, RuntimeType contextType);
127 [MethodImplAttribute(MethodImplOptions.InternalCall)]
128 static unsafe extern internal void SetValueDirect (RuntimeFieldInfo field, RuntimeType fieldType, void* pTypedRef, Object value, RuntimeType contextType);