public override IValue GetPropValue(int propNum) { var prop = _props[propNum]; var dispId = prop.DispatchId; try { try { var result = DispatchUtility.Invoke(Instance, dispId, null); return(CreateIValue(result)); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException ?? e; } } catch (System.MissingMemberException) { throw RuntimeException.PropNotFoundException(prop.Name); } catch (System.MemberAccessException) { throw RuntimeException.PropIsNotReadableException(prop.Name); } }
public override IValue GetIndexedValue(IValue index) { if (index.DataType != DataType.String) { throw RuntimeException.InvalidArgumentType(); } var n = FindProperty(index.AsString()); if (IsPropReadable(n)) { return(GetPropValue(n)); } else { throw RuntimeException.PropIsNotReadableException(index.AsString()); } }
public override IValue GetPropValue(int propNum) { try { try { var result = DispatchUtility.Invoke(_instance, propNum, null); return(CreateIValue(result)); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException; } } catch (System.MissingMemberException) { throw RuntimeException.PropNotFoundException("dispid[" + propNum.ToString() + "]"); } catch (System.MemberAccessException) { throw RuntimeException.PropIsNotReadableException("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; } }