public PropertyReference(EvaluationContext ctx, TargetPropertyInfo prop, TargetStructObject thisobj) : base(ctx) { this.prop = prop; if (!prop.IsStatic) { this.thisobj = thisobj; } }
// Note - this is public because we use it in weak referenced situations public void OnValueChanged(object sender, EventArgs eventArgs) { var target = Target; if (target == null) { MvxBindingTrace.Trace("Null weak reference target seen during OnValueChanged - unusual as usually Target is the sender of the value changed. Ignoring the value changed"); return; } var value = TargetPropertyInfo.GetGetMethod().Invoke(target, null); FireValueChanged(value); }
protected override void Dispose(bool isDisposing) { if (isDisposing) { // if the target property should be set to NULL on dispose then we clear it here // this is a fix for the possible memory leaks discussion started https://github.com/slodge/MvvmCross/issues/17#issuecomment-8527392 var setToNullAttribute = TargetPropertyInfo.GetCustomAttribute <MvxSetToNullAfterBindingAttribute>(true); if (setToNullAttribute != null) { SetValue(null); } } base.Dispose(isDisposing); }
public static ValueReference CreateIndexerValueReference(MdbEvaluationContext ctx, TargetObject target, TargetObject[] index) { TargetFundamentalObject mstr = target as TargetFundamentalObject; if (mstr != null && mstr.TypeName == "string") { // Special case for strings string name = "[" + ctx.Evaluator.TargetObjectToExpression(ctx, index[0]) + "]"; string val = (string)mstr.GetObject(ctx.Thread); object oo = ctx.Adapter.TargetObjectToObject(ctx, index[0]); int idx = (int)Convert.ChangeType(oo, typeof(int)); return(LiteralValueReference.CreateObjectLiteral(ctx, name, val [idx])); } TargetStructObject sob = target as TargetStructObject; if (sob == null) { return(null); } TargetPropertyInfo indexerProp = null; foreach (MemberReference mem in ObjectUtil.GetTypeMembers(ctx, target.Type, false, true, true, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)) { if (mem.Member.IsStatic) { continue; } if (mem.Member is TargetPropertyInfo) { TargetPropertyInfo prop = (TargetPropertyInfo)mem.Member; if (prop.CanRead && prop.Getter.ParameterTypes.Length == 1) { indexerProp = prop; break; } } } if (indexerProp != null) { return(new IndexerValueReference(ctx, sob, index, indexerProp)); } else { return(null); } }
protected string FormatProperty(string prefix, TargetPropertyInfo prop, bool is_static, Hashtable hash) { StringBuilder sb = new StringBuilder(); sb.Append(FormatMember(prefix, prop, is_static, hash)); sb.Append(" {"); if (prop.CanRead) { sb.Append(" get;"); } if (prop.CanWrite) { sb.Append(" set;"); } sb.Append(" };\n"); return(sb.ToString()); }
public static EvaluationResult GetProperty(Thread thread, TargetPropertyInfo property, TargetStructObject instance, EvaluationFlags flags, int timeout, out string error, out TargetObject result) { error = null; RuntimeInvokeResult rti; try { RuntimeInvokeFlags rti_flags = RuntimeInvokeFlags.VirtualMethod; if ((flags & EvaluationFlags.NestedBreakStates) != 0) { rti_flags |= RuntimeInvokeFlags.NestedBreakStates; } rti = thread.RuntimeInvoke( property.Getter, instance, new TargetObject [0], rti_flags); if (!rti.CompletedEvent.WaitOne(timeout, false)) { rti.Abort(); result = null; return(EvaluationResult.Timeout); } if ((rti.TargetException != null) && (rti.TargetException.Type == TargetError.ClassNotInitialized)) { result = null; error = rti.ExceptionMessage; return(EvaluationResult.NotInitialized); } if (rti.Result is Exception) { result = null; error = ((Exception)rti.Result).Message; return(EvaluationResult.UnknownError); } result = (TargetObject)rti.ReturnObject; if (rti.ExceptionMessage != null) { error = rti.ExceptionMessage; return(EvaluationResult.Exception); } else if (rti.ReturnObject == null) { rti.Abort(); return(EvaluationResult.UnknownError); } return(EvaluationResult.Ok); } catch (TargetException ex) { result = null; error = ex.ToString(); return(EvaluationResult.UnknownError); } }
public EE.EvaluationResult GetProperty(Thread thread, TargetPropertyInfo property, TargetStructObject instance, EE.EvaluationFlags flags, int timeout, out string error, out TargetObject value) { return(EE.GetProperty(thread, property, instance, flags, timeout, out error, out value)); }
public IndexerValueReference(EvaluationContext ctx, TargetStructObject target, TargetObject[] index, TargetPropertyInfo indexerProp) : base(ctx) { this.indexer = indexerProp; this.target = target; this.index = index; }