public override void SetIndexedValue(IValue index, IValue val) { if (index.DataType != DataType.String) { throw RuntimeException.InvalidArgumentType(); } var n = FindProperty(index.AsString()); if (IsPropWritable(n)) { SetPropValue(n, val); } else { throw RuntimeException.PropIsNotWritableException(index.AsString()); } }
public override void SetPropValue(int propNum, IValue newVal) { var prop = _props[propNum]; var dispId = prop.DispatchId; try { try { object argToPass; if (newVal.DataType == Machine.DataType.Date) { var date = newVal.AsDate(); if (date == DateTime.MinValue) { argToPass = new DateTime(100, 1, 1); // Min OLEAuth Date } else { argToPass = MarshalIValue(newVal); } } else { argToPass = MarshalIValue(newVal); } DispatchUtility.InvokeSetProperty(Instance, dispId, argToPass); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException ?? e; } } catch (System.MissingMemberException) { throw RuntimeException.PropNotFoundException(prop.Name); } catch (System.MemberAccessException) { throw RuntimeException.PropIsNotWritableException(prop.Name); } }
public override void SetPropValue(int propNum, IValue newVal) { try { try { object argToPass; if (newVal.DataType == Machine.DataType.Date) { var date = newVal.AsDate(); if (date == DateTime.MinValue) { argToPass = new DateTime(100, 1, 1); // Min OLEAuth Date } else { argToPass = MarshalIValue(newVal); } } else { argToPass = MarshalIValue(newVal); } DispatchUtility.InvokeSetProperty(_instance, propNum, argToPass); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException; } } catch (System.MissingMemberException) { throw RuntimeException.PropNotFoundException("dispid[" + propNum.ToString() + "]"); } catch (System.MemberAccessException) { throw RuntimeException.PropIsNotWritableException("dispid[" + propNum.ToString() + "]"); } }
public override void SetPropValue(int propNum, IValue newVal) { try { try { DispatchUtility.InvokeSetProperty(_instance, propNum, MarshalIValue(newVal)); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException; } } catch (System.MissingMemberException) { throw RuntimeException.PropNotFoundException("dispid[" + propNum.ToString() + "]"); } catch (System.MemberAccessException) { throw RuntimeException.PropIsNotWritableException("dispid[" + propNum.ToString() + "]"); } }
public PropertyTarget(PropertyInfo propInfo) { var attrib = (ContextPropertyAttribute)propInfo.GetCustomAttributes(typeof(ContextPropertyAttribute), false)[0]; _name = attrib.GetName(); _alias = attrib.GetAlias(); Func <TInstance, IValue> cantReadAction = (inst) => { throw RuntimeException.PropIsNotReadableException(_name); }; Action <TInstance, IValue> cantWriteAction = (inst, val) => { throw RuntimeException.PropIsNotWritableException(_name); }; this.CanRead = attrib.CanRead; this.CanWrite = attrib.CanWrite; if (attrib.CanRead) { var getMethodInfo = propInfo.GetGetMethod(); if (getMethodInfo == null) { _getter = cantReadAction; } else { var genericGetter = typeof(PropertyTarget <TInstance>).GetMembers(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .Where(x => x.MemberType == System.Reflection.MemberTypes.Method && x.Name == "CreateGetter") .Select(x => (System.Reflection.MethodInfo)x) .First(); var resolvedGetter = genericGetter.MakeGenericMethod(new Type[] { propInfo.PropertyType }); _getter = (Func <TInstance, IValue>)resolvedGetter.Invoke(this, new object[] { getMethodInfo }); } } else { _getter = cantReadAction; } if (attrib.CanWrite) { var setMethodInfo = propInfo.GetSetMethod(); if (setMethodInfo == null) { _setter = cantWriteAction; } else { var genericSetter = typeof(PropertyTarget <TInstance>).GetMembers(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .Where(x => x.MemberType == System.Reflection.MemberTypes.Method && x.Name == "CreateSetter") .Select(x => (System.Reflection.MethodInfo)x) .First(); var resolvedSetter = genericSetter.MakeGenericMethod(new Type[] { propInfo.PropertyType }); _setter = (Action <TInstance, IValue>)resolvedSetter.Invoke(this, new object[] { setMethodInfo }); } } else { _setter = cantWriteAction; } }
public override void SetPropValue(int propNum, IValue newVal) { throw RuntimeException.PropIsNotWritableException($"{propNum}"); }
public override void SetIndexedValue(IValue index, IValue val) { throw RuntimeException.PropIsNotWritableException(index.AsString()); }