/// <summary> /// Sets the value of the property /// </summary> /// <param name="script">The script.</param> /// <param name="obj">The object.</param> /// <param name="v">The value to set.</param> public void SetValue <T>(Script script, T obj, DynValue v) { this.CheckAccess(MemberDescriptorAccess.CanWrite, obj); if (m_Setter == null) { throw new ScriptRuntimeException("userdata property '{0}.{1}' cannot be written to.", this.PropertyInfo.DeclaringType.Name, this.Name); } object value = ScriptToClrConversions.DynValueToObject(v); try { if (value is double) { value = NumericConversions.DoubleToType(PropertyInfo.PropertyType, (double)value); } if (AccessMode == InteropAccessMode.LazyOptimized && m_OptimizedSetter == null) { OptimizeSetter(); } if (m_OptimizedSetter != null) { m_OptimizedSetter(obj, value); } else { m_Setter.Invoke(IsStatic ? default(T) : obj, new object[] { value }); // convoluted workaround for --full-aot Mono execution } } catch (ArgumentException) { // non-optimized setters fall here throw ScriptRuntimeException.UserDataArgumentTypeMismatch(v.Type, PropertyInfo.PropertyType); } catch (InvalidCastException) { // optimized setters fall here throw ScriptRuntimeException.UserDataArgumentTypeMismatch(v.Type, PropertyInfo.PropertyType); } }
/// <summary> /// Converts this MoonSharp DynValue to a CLR object, marked as dynamic /// </summary> public dynamic ToDynamic() { return(ScriptToClrConversions.DynValueToObject(this)); }
/// <summary> /// Converts this MoonSharp DynValue to a CLR object. /// </summary> public object ToObject() { return(ScriptToClrConversions.DynValueToObject(this)); }