X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Reflection%2FMonoField.cs;h=2b3894dd0ff693c5270ff53f025db433238acc20;hb=4323fbeaebf249f016dfdd6dc9b3b52a515f87c4;hp=b7d35a97d518978377ac0689c855a6612e073c8f;hpb=38f320d19a29a3e7d6a92cdb0b3ebec149d7c1a7;p=mono.git diff --git a/mcs/class/corlib/System.Reflection/MonoField.cs b/mcs/class/corlib/System.Reflection/MonoField.cs index b7d35a97d51..2b3894dd0ff 100644 --- a/mcs/class/corlib/System.Reflection/MonoField.cs +++ b/mcs/class/corlib/System.Reflection/MonoField.cs @@ -36,10 +36,12 @@ using System; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Serialization; namespace System.Reflection { - - internal class MonoField : FieldInfo { + + [Serializable] + internal class MonoField : FieldInfo, ISerializable { internal IntPtr klass; internal RuntimeFieldHandle fhandle; string name; @@ -101,6 +103,9 @@ namespace System.Reflection { public override object GetValue (object obj) { + if (!IsStatic && obj == null) + throw new TargetException ("Non-static field requires a target"); + CheckGeneric (); return GetValueInternal (obj); } @@ -114,9 +119,12 @@ namespace System.Reflection { public override void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture) { if (!IsStatic && obj == null) - throw new ArgumentNullException ("obj"); + throw new TargetException ("Non-static field requires a target"); + if (IsLiteral) + throw new FieldAccessException ("Cannot set a constant field"); if (binder == null) binder = Binder.DefaultBinder; + CheckGeneric (); if (val != null) { object newVal; newVal = binder.ChangeType (val, type, culture); @@ -138,9 +146,23 @@ namespace System.Reflection { return field; } -#if NET_2_0 || BOOTSTRAP_NET_2_0 + // ISerializable + public void GetObjectData (SerializationInfo info, StreamingContext context) + { + MemberInfoSerializationHolder.Serialize (info, Name, ReflectedType, + ToString(), MemberTypes.Field); + } + +#if NET_2_0 [MethodImplAttribute(MethodImplOptions.InternalCall)] - public override extern FieldInfo Mono_GetGenericFieldDefinition (); + public override extern object GetRawConstantValue (); +#endif + + void CheckGeneric () { +#if NET_2_0 + if (DeclaringType.ContainsGenericParameters) + throw new InvalidOperationException ("Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true."); #endif + } } }