Esempio n. 1
0
 public override void SetValue(object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
 {
     if (!IsStatic)
     {
         if (obj == null)
         {
             throw new TargetException("Non-static field requires a target");
         }
         if (!DeclaringType.IsAssignableFrom(obj.GetType()))
         {
             throw new ArgumentException(string.Format(
                                             "Field {0} defined on type {1} is not a field on the target object which is of type {2}.",
                                             Name, DeclaringType, obj.GetType()),
                                         "obj");
         }
     }
     if (IsLiteral)
     {
         throw new FieldAccessException("Cannot set a constant field");
     }
     if (binder == null)
     {
         binder = Binder.DefaultBinder;
     }
     CheckGeneric();
     if (val != null)
     {
         val = binder.ConvertValue(val, FieldType, culture, (invokeAttr & BindingFlags.ExactBinding) != 0);
     }
     SetValueInternal(this, obj, val);
 }
Esempio n. 2
0
		public override void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
		{
			if (!IsStatic) {
				if (obj == null)
					throw new TargetException ("Non-static field requires a target");
				if (!DeclaringType.IsAssignableFrom (obj.GetType ()))
					throw new ArgumentException (string.Format (
						"Field {0} defined on type {1} is not a field on the target object which is of type {2}.",
					 	Name, DeclaringType, obj.GetType ()),
					 	"obj");
			}
			if (IsLiteral)
				throw new FieldAccessException ("Cannot set a constant field");
			if (binder == null)
				binder = Binder.DefaultBinder;
			CheckGeneric ();
			if (val != null) {
				val = binder.ConvertValue (val, FieldType, culture, (invokeAttr & BindingFlags.ExactBinding) != 0);
			}
			SetValueInternal (this, obj, val);
		}