private object CallMethod(string name, object[] parameters, bool enableOutArgs, out object[] outArgs, EvaluationOptions options) { var localContext = ctx.WithOptions(options); var argValues = new object [parameters.Length]; var argTypes = new object [parameters.Length]; for (int n = 0; n < argValues.Length; n++) { argValues[n] = localContext.Adapter.FromRawValue(localContext, parameters[n]); argTypes[n] = localContext.Adapter.GetValueType(localContext, argValues[n]); } var type = localContext.Adapter.GetValueType(localContext, targetObject); if (enableOutArgs) { object[] outArgsTemp; var res = localContext.Adapter.RuntimeInvoke(localContext, type, targetObject, name, null, argTypes, argValues, out outArgsTemp); outArgs = new object[outArgsTemp.Length]; for (int i = 0; i < outArgs.Length; i++) { outArgs [i] = localContext.Adapter.ToRawValue(localContext, null, outArgsTemp [i]); } return(localContext.Adapter.ToRawValue(localContext, null, res)); } else { outArgs = null; var res = localContext.Adapter.RuntimeInvoke(localContext, type, targetObject, name, argTypes, argValues); return(localContext.Adapter.ToRawValue(localContext, null, res)); } }
public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options) { EvaluationContext cctx = ctx.WithOptions(options); object tdataType = null; TypeDisplayData tdata = null; List <ObjectValue> list = new List <ObjectValue> (); foreach (ValueReference val in cctx.Adapter.GetMembersSorted(cctx, objectSource, type, obj, bindingFlags)) { object decType = val.DeclaringType; if (decType != null && decType != tdataType) { tdataType = decType; tdata = cctx.Adapter.GetTypeDisplayData(cctx, decType); } DebuggerBrowsableState state = tdata.GetMemberBrowsableState(val.Name); if (state == DebuggerBrowsableState.Never) { continue; } ObjectValue oval = val.CreateObjectValue(options); list.Add(oval); } if ((bindingFlags & BindingFlags.NonPublic) == 0) { BindingFlags newFlags = bindingFlags | BindingFlags.NonPublic; newFlags &= ~BindingFlags.Public; list.Add(CreateNonPublicsNode(cctx, objectSource, type, obj, newFlags)); } return(list.ToArray()); }
public ObjectValue GetValue(ObjectPath path, EvaluationOptions options) { EvaluationContext c = ctx.WithOptions(options); ObjectValue[] vals = c.Adapter.GetExpressionValuesAsync(c, new string[] { path.LastName }); return(vals[0]); }
public object GetRawValue(ObjectPath path, EvaluationOptions options) { int idx = int.Parse(path.LastName.Replace("[", "").Replace("]", "")); EvaluationContext cctx = ctx.WithOptions(options); return(cctx.Adapter.ToRawValue(cctx, new EnumerableObjectSource(this, idx), GetElement(idx))); }
public object CallMethod(string name, object[] parameters, EvaluationOptions options) { EvaluationContext localContext = ctx.WithOptions(options); object[] argValues = new object [parameters.Length]; object[] argTypes = new object [parameters.Length]; for (int n = 0; n < argValues.Length; n++) { argValues[n] = localContext.Adapter.FromRawValue(localContext, parameters[n]); argTypes[n] = localContext.Adapter.GetValueType(localContext, argValues[n]); } object type = localContext.Adapter.GetValueType(localContext, targetObject); object res = localContext.Adapter.RuntimeInvoke(localContext, type, targetObject, name, argTypes, argValues); return(localContext.Adapter.ToRawValue(localContext, null, res)); }
public ObjectValue[] GetChildren(ObjectPath path, int firstItemIndex, int count, EvaluationOptions options) { EvaluationContext cctx = ctx.WithOptions(options); if (path.Length > 1) { // Looking for children of an array element int[] idx = StringToIndices(path [1]); object obj = array.GetElement(idx); return(cctx.Adapter.GetObjectValueChildren(cctx, new ArrayObjectSource(array, path[1]), obj, firstItemIndex, count)); } int lowerBound; int upperBound; bool isLastDimension; if (dimensions.Length > 1) { int rank = baseIndices.Length; lowerBound = array.GetLowerBounds() [rank]; upperBound = lowerBound + dimensions [rank] - 1; isLastDimension = rank == dimensions.Length - 1; } else { lowerBound = array.GetLowerBounds() [0]; upperBound = lowerBound + dimensions [0] - 1; isLastDimension = true; } int len; int initalIndex; if (!IsRange) { initalIndex = lowerBound; len = upperBound + 1 - lowerBound; } else { initalIndex = firstIndex; len = lastIndex - firstIndex + 1; } if (firstItemIndex == -1) { firstItemIndex = 0; count = len; } // Make sure the group doesn't have too many elements. If so, divide int div = 1; while (len / div > MaxChildCount) { div *= 10; } if (div == 1 && isLastDimension) { // Return array elements ObjectValue[] values = new ObjectValue [count]; ObjectPath newPath = new ObjectPath("this"); int[] curIndex = new int [baseIndices.Length + 1]; Array.Copy(baseIndices, curIndex, baseIndices.Length); string curIndexStr = IndicesToString(baseIndices); if (baseIndices.Length > 0) { curIndexStr += ","; } curIndex [curIndex.Length - 1] = initalIndex + firstItemIndex; var elems = array.GetElements(curIndex, System.Math.Min(values.Length, upperBound - lowerBound + 1)); for (int n = 0; n < values.Length; n++) { int index = n + initalIndex + firstItemIndex; string sidx = curIndexStr + index; ObjectValue val; string ename = "[" + sidx.Replace(",", ", ") + "]"; if (index > upperBound) { val = ObjectValue.CreateUnknown(sidx); } else { curIndex [curIndex.Length - 1] = index; val = cctx.Adapter.CreateObjectValue(cctx, this, newPath.Append(sidx), elems.GetValue(n), ObjectValueFlags.ArrayElement); if (elems.GetValue(n) != null && !cctx.Adapter.IsNull(cctx, elems.GetValue(n))) { TypeDisplayData tdata = cctx.Adapter.GetTypeDisplayData(cctx, cctx.Adapter.GetValueType(cctx, elems.GetValue(n))); if (!string.IsNullOrEmpty(tdata.NameDisplayString)) { try { ename = cctx.Adapter.EvaluateDisplayString(cctx, elems.GetValue(n), tdata.NameDisplayString); } catch (MissingMemberException) { // missing property or otherwise malformed DebuggerDisplay string } } } } val.Name = ename; values [n] = val; } return(values); } if (!isLastDimension && div == 1) { // Return an array element group for each index var list = new List <ObjectValue> (); for (int i = 0; i < count; i++) { int index = i + initalIndex + firstItemIndex; ObjectValue val; // This array must be created at every call to avoid sharing // changes with all array groups int[] curIndex = new int [baseIndices.Length + 1]; Array.Copy(baseIndices, curIndex, baseIndices.Length); curIndex [curIndex.Length - 1] = index; if (index > upperBound) { val = ObjectValue.CreateUnknown(""); } else { ArrayElementGroup grp = new ArrayElementGroup(cctx, array, curIndex); val = grp.CreateObjectValue(); } list.Add(val); } return(list.ToArray()); } else { // Too many elements. Split the array. // Don't make divisions of 10 elements, min is 100 if (div == 10) { div = 100; } // Create the child groups int i = initalIndex + firstItemIndex; len += i; var list = new List <ObjectValue> (); while (i < len) { int end = i + div - 1; if (end >= len) { end = len - 1; } ArrayElementGroup grp = new ArrayElementGroup(cctx, array, baseIndices, i, end); list.Add(grp.CreateObjectValue()); i += div; } return(list.ToArray()); } }
public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options) { EvaluationContext cctx = ctx.WithOptions(options); return(cctx.Adapter.GetObjectValueChildren(cctx, objectSource, type, obj, index, count, false)); }
public EvaluationContext GetContext(EvaluationOptions options) { return(Context.WithOptions(options)); }
public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options) { options = options.Clone(); options.EllipsizeStrings = false; options.AllowTargetInvoke = true; ctx = ctx.WithOptions(options); string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue); var excInstance = Exception.CreateObjectValue(withTimeout, options); excInstance.Name = "Instance"; ObjectValue messageValue = null; ObjectValue helpLinkValue = null; var exceptionType = ctx.Adapter.GetValueType(ctx, Exception.Value); // Get the message if (withTimeout) { messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message"); if (mref != null) { string val = (string)mref.ObjectValue; return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal)); } return(ObjectValue.CreateUnknown("Message")); }); } else { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message"); if (mref != null) { string val = (string)mref.ObjectValue; messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal); } } if (messageValue == null) { messageValue = ObjectValue.CreateUnknown("Message"); } messageValue.Name = "Message"; // Get the help link if (withTimeout) { helpLinkValue = ctx.Adapter.CreateObjectValueAsync("HelpLink", ObjectValueFlags.None, delegate { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink"); if (mref != null) { string val = (string)mref.ObjectValue; return(ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal)); } return(ObjectValue.CreateUnknown("HelpLink")); }); } else { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink"); if (mref != null) { string val = (string)mref.ObjectValue; helpLinkValue = ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal); } } if (helpLinkValue == null) { helpLinkValue = ObjectValue.CreateUnknown("HelpLink"); } helpLinkValue.Name = "HelpLink"; // Inner exception ObjectValue childExceptionValue = null; if (withTimeout) { childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate { var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException"); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { //Console.WriteLine ("pp got child:" + type); var innerSource = new ExceptionInfoSource(ctx, inner); var res = innerSource.CreateObjectValue(false, options); return(res); } return(ObjectValue.CreateUnknown("InnerException")); }); } else { var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException"); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { //Console.WriteLine ("pp got child:" + type); var innerSource = new ExceptionInfoSource(ctx, inner); childExceptionValue = innerSource.CreateObjectValue(false, options); childExceptionValue.Name = "InnerException"; } } if (childExceptionValue == null) { childExceptionValue = ObjectValue.CreateUnknown("InnerException"); } // Inner exceptions in case of AgregatedException ObjectValue childExceptionsValue = null; ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate { var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerExceptions"); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { var obj = inner.GetValue(ctx); var objType = ctx.Adapter.GetValueType(ctx, obj); var count = (int)ctx.Adapter.GetMember(ctx, null, obj, "Count").ObjectValue; var childrenList = new List <ObjectValue>(); for (int i = 0; i < count; i++) { childrenList.Add(new ExceptionInfoSource(ctx, ctx.Adapter.GetIndexerReference(ctx, obj, objType, new object[] { ctx.Adapter.CreateValue(ctx, i) })).CreateObjectValue(withTimeout, ctx.Options)); } return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray())); } return(ObjectValue.CreateUnknown("InnerExceptions")); }; if (withTimeout) { childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate); } else { childExceptionsValue = getInnerExceptionsDelegate(); } if (childExceptionsValue == null) { childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions"); } // Stack trace ObjectValue stackTraceValue; if (withTimeout) { stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate { var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace"); if (stackTrace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } return(GetStackTrace(stackTrace.ObjectValue as string)); }); } else { var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace"); if (stackTrace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } stackTraceValue = GetStackTrace(stackTrace.ObjectValue as string); } var children = new ObjectValue [] { excInstance, messageValue, helpLinkValue, stackTraceValue, childExceptionValue, childExceptionsValue }; return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children)); }