コード例 #1
0
        public ObjectValue CreateObjectValue(EvaluationOptions options)
        {
            if (!CanEvaluate(options))
            {
                return(DC.ObjectValue.CreateImplicitNotSupported(this, new ObjectPath(Name), ctx.Adapter.GetTypeName(GetContext(options), Type), Flags));
            }

            Connect();
            try
            {
                return(OnCreateObjectValue(options));
            }
            catch (ImplicitEvaluationDisabledException)
            {
                return(DC.ObjectValue.CreateImplicitNotSupported(this, new ObjectPath(Name), ctx.Adapter.GetTypeName(GetContext(options), Type), Flags));
            }
            catch (NotSupportedExpressionException ex)
            {
                return(DC.ObjectValue.CreateNotSupported(this, new ObjectPath(Name), ex.Message, ctx.Adapter.GetTypeName(GetContext(options), Type), Flags));
            }
            catch (EvaluatorException ex)
            {
                return(DC.ObjectValue.CreateError(this, new ObjectPath(Name), "", ex.Message, Flags));
            }
            catch (Exception ex)
            {
                ctx.WriteDebuggerError(ex);
                return(DC.ObjectValue.CreateUnknown(Name));
            }
        }
コード例 #2
0
 public ObjectValue GetExpressionValue(EvaluationContext ctx, string exp)
 {
     try {
         ValueReference var = ctx.Evaluator.Evaluate(ctx, exp);
         if (var != null)
         {
             return(var.CreateObjectValue(ctx.Options));
         }
         else
         {
             return(ObjectValue.CreateUnknown(exp));
         }
     }
     catch (ImplicitEvaluationDisabledException) {
         return(ObjectValue.CreateImplicitNotSupported(ctx.ExpressionValueSource, new ObjectPath(exp), "", ObjectValueFlags.None));
     }
     catch (NotSupportedExpressionException ex) {
         return(ObjectValue.CreateNotSupported(ctx.ExpressionValueSource, new ObjectPath(exp), ex.Message, "", ObjectValueFlags.None));
     }
     catch (EvaluatorException ex) {
         return(ObjectValue.CreateError(ctx.ExpressionValueSource, new ObjectPath(exp), "", ex.Message, ObjectValueFlags.None));
     }
     catch (Exception ex) {
         ctx.WriteDebuggerError(ex);
         return(ObjectValue.CreateUnknown(exp));
     }
 }
コード例 #3
0
        public EvaluationResult SetValue(ObjectPath path, string value, EvaluationOptions options)
        {
            if (path.Length != 2)
            {
                throw new NotSupportedException();
            }

            int[] idx = StringToIndices(path [1]);

            object val;

            try {
                EvaluationContext cctx = ctx.Clone();
                EvaluationOptions ops  = options ?? cctx.Options;
                ops.AllowMethodEvaluation = true;
                ops.AllowTargetInvoke     = true;
                cctx.Options = ops;
                ValueReference var = ctx.Evaluator.Evaluate(ctx, value, array.ElementType);
                val = var.Value;
                val = ctx.Adapter.Convert(ctx, val, array.ElementType);
                array.SetElement(idx, val);
            } catch {
                val = array.GetElement(idx);
            }
            try {
                return(ctx.Evaluator.TargetObjectToExpression(ctx, val));
            } catch (Exception ex) {
                ctx.WriteDebuggerError(ex);
                return(new EvaluationResult("? (" + ex.Message + ")"));
            }
        }
コード例 #4
0
		public ObjectValue CreateObjectValue (EvaluationContext ctx, IObjectValueSource source, ObjectPath path, object obj, ObjectValueFlags flags)
		{
			try {
				return CreateObjectValueImpl (ctx, source, path, obj, flags);
			} catch (Exception ex) {
				ctx.WriteDebuggerError (ex);
				return ObjectValue.CreateFatalError (path.LastName, ex.Message, flags);
			}
		}
コード例 #5
0
        public object GetProxyObject(EvaluationContext ctx, object obj)
        {
            TypeDisplayData data = GetTypeDisplayData(ctx, GetValueType(ctx, obj));

            if (string.IsNullOrEmpty(data.ProxyType) || !ctx.Options.AllowDebuggerProxy)
            {
                return(obj);
            }

            object[] typeArgs = null;

            int i = data.ProxyType.IndexOf('`');

            if (i != -1)
            {
                // The proxy type is an uninstantiated generic type.
                // The number of type args of the proxy must match the args of the target object
                int j = i + 1;
                for (; j < data.ProxyType.Length && char.IsDigit(data.ProxyType[j]); j++)
                {
                    ;
                }
                int np = int.Parse(data.ProxyType.Substring(i + 1, j - i - 1));
                typeArgs = GetTypeArgs(ctx, GetValueType(ctx, obj));
                if (typeArgs.Length != np)
                {
                    return(obj);
                }
            }

            object ttype = GetType(ctx, data.ProxyType, typeArgs);

            if (ttype == null)
            {
                i = data.ProxyType.IndexOf(',');
                if (i != -1)
                {
                    ttype = GetType(ctx, data.ProxyType.Substring(0, i).Trim(), typeArgs);
                }
            }
            if (ttype == null)
            {
                throw new EvaluatorException("Unknown type '{0}'", data.ProxyType);
            }

            try {
                object val = CreateValue(ctx, ttype, obj);
                return(val ?? obj);
            } catch (Exception ex) {
                ctx.WriteDebuggerError(ex);
                return(obj);
            }
        }
コード例 #6
0
 public ObjectValue CreateObjectValue(EvaluationOptions options)
 {
     if (!CanEvaluate(options))
     {
         if (options.AllowTargetInvoke)                //If it can't evaluate and target invoke is allowed, mark it as not supported.
         {
             return(DC.ObjectValue.CreateNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), "Can not evaluate", Flags));
         }
         return(DC.ObjectValue.CreateImplicitNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), Flags));
     }
     Connect();
     try {
         return(OnCreateObjectValue(options));
     } catch (ImplicitEvaluationDisabledException) {
         return(DC.ObjectValue.CreateImplicitNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), Flags));
     } catch (NotSupportedExpressionException ex) {
         return(DC.ObjectValue.CreateNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), ex.Message, Flags));
     } catch (EvaluatorException ex) {
         return(DC.ObjectValue.CreateError(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), ex.Message, Flags));
     } catch (Exception ex) {
         Context.WriteDebuggerError(ex);
         return(DC.ObjectValue.CreateUnknown(Name));
     }
 }
コード例 #7
0
		public TypeDisplayData GetTypeDisplayData (EvaluationContext ctx, object type)
		{
			if (!IsClass (type))
				return TypeDisplayData.Default;

			TypeDisplayData td;
			string tname = GetTypeName (ctx, type);
			if (typeDisplayData.TryGetValue (tname, out td))
				return td;

			try {
				td = OnGetTypeDisplayData (ctx, type);
			}
			catch (Exception ex) {
				ctx.WriteDebuggerError (ex);
			}
			if (td == null)
				typeDisplayData[tname] = td = TypeDisplayData.Default;
			else
				typeDisplayData[tname] = td;
			return td;
		}
コード例 #8
0
		public object GetProxyObject (EvaluationContext ctx, object obj)
		{
			TypeDisplayData data = GetTypeDisplayData (ctx, GetValueType (ctx, obj));
			if (string.IsNullOrEmpty (data.ProxyType) || !ctx.Options.AllowDebuggerProxy)
				return obj;

			object[] typeArgs = null;

			int i = data.ProxyType.IndexOf ('`');
			if (i != -1) {
				// The proxy type is an uninstantiated generic type.
				// The number of type args of the proxy must match the args of the target object
				int j = i + 1;
				for (; j < data.ProxyType.Length && char.IsDigit (data.ProxyType[j]); j++);
				int np = int.Parse (data.ProxyType.Substring (i + 1, j - i - 1));
				typeArgs = GetTypeArgs (ctx, GetValueType (ctx, obj));
				if (typeArgs.Length != np)
					return obj;
			}
			
			object ttype = GetType (ctx, data.ProxyType, typeArgs);
			if (ttype == null) {
				i = data.ProxyType.IndexOf (',');
				if (i != -1)
					ttype = GetType (ctx, data.ProxyType.Substring (0, i).Trim (), typeArgs);
			}
			if (ttype == null)
				throw new EvaluatorException ("Unknown type '{0}'", data.ProxyType);

			try {
				object val = CreateValue (ctx, ttype, obj);
				return val ?? obj;
			} catch (Exception ex) {
				ctx.WriteDebuggerError (ex);
				return obj;
			}
		}
コード例 #9
0
		public virtual CompletionData GetExpressionCompletionData (EvaluationContext ctx, string exp)
		{
			int i;
			if (exp.Length == 0)
				return null;

			if (exp [exp.Length - 1] == '.') {
				exp = exp.Substring (0, exp.Length - 1);
				i = 0;
				while (i < exp.Length) {
					ValueReference vr = null;
					try {
						vr = ctx.Evaluator.Evaluate (ctx, exp.Substring (i), null);
						if (vr != null) {
							CompletionData data = new CompletionData ();
							foreach (ValueReference cv in vr.GetChildReferences (ctx.Options))
								data.Items.Add (new CompletionItem (cv.Name, cv.Flags));
							data.ExpressionLenght = 0;
							return data;
						}
					} catch (Exception ex) {
						ctx.WriteDebuggerError (ex);
					}
					i++;
				}
				return null;
			}
			
			i = exp.Length - 1;
			bool lastWastLetter = false;
			while (i >= 0) {
				char c = exp [i--];
				if (!char.IsLetterOrDigit (c) && c != '_')
					break;
				lastWastLetter = !char.IsDigit (c);
			}
			if (lastWastLetter) {
				string partialWord = exp.Substring (i+1);
				
				CompletionData data = new CompletionData ();
				data.ExpressionLenght = partialWord.Length;
				
				// Local variables
				
				foreach (ValueReference vc in GetLocalVariables (ctx))
					if (vc.Name.StartsWith (partialWord))
						data.Items.Add (new CompletionItem (vc.Name, vc.Flags));
				
				// Parameters
				
				foreach (ValueReference vc in GetParameters (ctx))
					if (vc.Name.StartsWith (partialWord))
						data.Items.Add (new CompletionItem (vc.Name, vc.Flags));
				
				// Members
				
				ValueReference thisobj = GetThisReference (ctx);
				
				if (thisobj != null)
					data.Items.Add (new CompletionItem ("this", ObjectValueFlags.Field | ObjectValueFlags.ReadOnly));

				object type = GetEnclosingType (ctx);
				
				foreach (ValueReference vc in GetMembers (ctx, null, type, thisobj != null ? thisobj.Value : null))
					if (vc.Name.StartsWith (partialWord))
						data.Items.Add (new CompletionItem (vc.Name, vc.Flags));
				
				if (data.Items.Count > 0)
					return data;
			}
			return null;
		}
コード例 #10
0
		public virtual ObjectValue[] GetObjectValueChildren (EvaluationContext ctx, IObjectSource objectSource, object type, object obj, int firstItemIndex, int count, bool dereferenceProxy)
		{
			if (obj is EvaluationResult)
				return new ObjectValue[0];
			
			if (IsArray (ctx, obj)) {
				ArrayElementGroup agroup = new ArrayElementGroup (ctx, CreateArrayAdaptor (ctx, obj));
				return agroup.GetChildren (ctx.Options);
			}

			if (IsPrimitive (ctx, obj))
				return new ObjectValue[0];

			bool showRawView = false;
			
			// If there is a proxy, it has to show the members of the proxy
			object proxy = obj;
			if (dereferenceProxy) {
				proxy = GetProxyObject (ctx, obj);
				if (proxy != obj) {
					type = GetValueType (ctx, proxy);
					showRawView = true;
				}
			}

			TypeDisplayData tdata = GetTypeDisplayData (ctx, type);
			bool groupPrivateMembers = ctx.Options.GroupPrivateMembers && (ctx.Options.GroupUserPrivateMembers || IsExternalType (ctx, type));

			List<ObjectValue> values = new List<ObjectValue> ();
			BindingFlags flattenFlag = ctx.Options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
			BindingFlags nonNonPublicFlag = groupPrivateMembers || showRawView ? (BindingFlags)0 : BindingFlags.NonPublic;
			BindingFlags staticFlag = ctx.Options.GroupStaticMembers ? (BindingFlags)0 : BindingFlags.Static;
			BindingFlags access = BindingFlags.Public | BindingFlags.Instance | flattenFlag | nonNonPublicFlag | staticFlag;
			
			// Load all members to a list before creating the object values,
			// to avoid problems with objects being invalidated due to evaluations in the target,
			List<ValueReference> list = new List<ValueReference> ();
			list.AddRange (GetMembersSorted (ctx, objectSource, type, proxy, access));
			var names = new ObjectValueNameTracker (ctx);
			object tdataType = type;
			
			foreach (ValueReference val in list) {
				try {
					object decType = val.DeclaringType;
					if (decType != null && decType != tdataType) {
						tdataType = decType;
						tdata = GetTypeDisplayData (ctx, decType);
					}
					DebuggerBrowsableState state = tdata.GetMemberBrowsableState (val.Name);
					if (state == DebuggerBrowsableState.Never)
						continue;

					if (state == DebuggerBrowsableState.RootHidden && dereferenceProxy) {
						object ob = val.Value;
						if (ob != null) {
							values.Clear ();
							values.AddRange (GetObjectValueChildren (ctx, val, ob, -1, -1));
							showRawView = true;
							break;
						}
					}
					else {
						ObjectValue oval = val.CreateObjectValue (true);
						names.Disambiguate (val, oval);
						values.Add (oval);
					}

				}
				catch (Exception ex) {
					ctx.WriteDebuggerError (ex);
					values.Add (ObjectValue.CreateError (null, new ObjectPath (val.Name), GetDisplayTypeName (GetTypeName (ctx, val.Type)), ex.Message, val.Flags));
				}
			}

			if (showRawView) {
				values.Add (RawViewSource.CreateRawView (ctx, objectSource, obj));
			}
			else {
				if (IsArray (ctx, proxy)) {
					ICollectionAdaptor col = CreateArrayAdaptor (ctx, proxy);
					ArrayElementGroup agroup = new ArrayElementGroup (ctx, col);
					ObjectValue val = ObjectValue.CreateObject (null, new ObjectPath ("Raw View"), "", "", ObjectValueFlags.ReadOnly, values.ToArray ());
					values = new List<ObjectValue> ();
					values.Add (val);
					values.AddRange (agroup.GetChildren (ctx.Options));
				}
				else {
					if (ctx.Options.GroupStaticMembers && HasMembers (ctx, type, proxy, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | flattenFlag)) {
						access = BindingFlags.Static | BindingFlags.Public | flattenFlag | nonNonPublicFlag;
						values.Add (FilteredMembersSource.CreateStaticsNode (ctx, objectSource, type, proxy, access));
					}
					if (groupPrivateMembers && HasMembers (ctx, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag))
						values.Add (FilteredMembersSource.CreateNonPublicsNode (ctx, objectSource, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag));
					
					if (!ctx.Options.FlattenHierarchy) {
						object baseType = GetBaseType (ctx, type, false);
						if (baseType != null)
							values.Insert (0, BaseTypeViewSource.CreateBaseTypeView (ctx, objectSource, baseType, proxy));
					}
				}
			}
			return values.ToArray ();
		}
コード例 #11
0
		public ObjectValue GetExpressionValue (EvaluationContext ctx, string exp)
		{
			try {
				ValueReference var = ctx.Evaluator.Evaluate (ctx, exp);
				if (var != null) {
					return var.CreateObjectValue (ctx.Options);
				}
				else
					return ObjectValue.CreateUnknown (exp);
			}
			catch (ImplicitEvaluationDisabledException) {
				return ObjectValue.CreateImplicitNotSupported (ctx.ExpressionValueSource, new ObjectPath (exp), "", ObjectValueFlags.None);
			}
			catch (NotSupportedExpressionException ex) {
				return ObjectValue.CreateNotSupported (ctx.ExpressionValueSource, new ObjectPath (exp), ex.Message, "", ObjectValueFlags.None);
			}
			catch (EvaluatorException ex) {
				return ObjectValue.CreateError (ctx.ExpressionValueSource, new ObjectPath (exp), "", ex.Message, ObjectValueFlags.None);
			}
			catch (Exception ex) {
				ctx.WriteDebuggerError (ex);
				return ObjectValue.CreateUnknown (exp);
			}
		}
コード例 #12
0
		public virtual bool ObjectValueHasChildren (EvaluationContext ctx, IObjectSource objectSource, object type, object obj, bool dereferenceProxy)
		{
			if (obj is EvaluationResult)
				return false;

			if (IsArray (ctx, obj))
				return true;

			if (IsPrimitive (ctx, obj))
				return false;

			bool showRawView = false;
			
			// If there is a proxy, it has to show the members of the proxy
			object proxy = obj;
			if (dereferenceProxy) {
				proxy = GetProxyObject (ctx, obj);
				if (proxy != obj) {
					type = GetValueType (ctx, proxy);
					showRawView = true;
				}
			}

			TypeDisplayData tdata = GetTypeDisplayData (ctx, type);
			bool groupPrivateMembers = ctx.Options.GroupPrivateMembers && (ctx.Options.GroupUserPrivateMembers || IsExternalType (ctx, type));
			BindingFlags flattenFlag = ctx.Options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
			BindingFlags nonNonPublicFlag = groupPrivateMembers || showRawView ? (BindingFlags)0 : BindingFlags.NonPublic;
			BindingFlags staticFlag = ctx.Options.GroupStaticMembers ? (BindingFlags)0 : BindingFlags.Static;
			BindingFlags access = BindingFlags.Public | BindingFlags.Instance | flattenFlag | nonNonPublicFlag | staticFlag;
			
			// Load all members to a list before creating the object values,
			// to avoid problems with objects being invalidated due to evaluations in the target,
			List<ValueReference> list = new List<ValueReference> ();
			list.AddRange (GetMembersSorted (ctx, objectSource, type, proxy, access));
			object tdataType = type;
			
			foreach (ValueReference val in list) {
				try {
					object decType = val.DeclaringType;
					if (decType != null && decType != tdataType) {
						tdataType = decType;
						tdata = GetTypeDisplayData (ctx, decType);
					}

					DebuggerBrowsableState state = tdata.GetMemberBrowsableState (val.Name);
					if (state == DebuggerBrowsableState.Never)
						continue;

					return true;
				} catch (Exception ex) {
					ctx.WriteDebuggerError (ex);
				}
			}

			if (IsArray (ctx, proxy))
				return true;

			if (ctx.Options.GroupStaticMembers && HasMembers (ctx, type, proxy, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | flattenFlag))
				return true;

			if (groupPrivateMembers && HasMembers (ctx, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag))
				return true;

			if (!ctx.Options.FlattenHierarchy) {
				object baseType = GetBaseType (ctx, type, false);
				if (baseType != null)
					return true;
			}

			return false;
		}
コード例 #13
0
        public virtual ObjectValue[] GetObjectValueChildren(EvaluationContext ctx, IObjectSource objectSource, object type, object obj, int firstItemIndex, int count, bool dereferenceProxy)
        {
            if (IsArray(ctx, obj))
            {
                ArrayElementGroup agroup = new ArrayElementGroup(ctx, CreateArrayAdaptor(ctx, obj));
                return(agroup.GetChildren(ctx.Options));
            }

            if (IsPrimitive(ctx, obj))
            {
                return(new ObjectValue[0]);
            }

            bool showRawView = false;

            // If there is a proxy, it has to show the members of the proxy
            object proxy = obj;

            if (dereferenceProxy)
            {
                proxy = GetProxyObject(ctx, obj);
                if (proxy != obj)
                {
                    type        = GetValueType(ctx, proxy);
                    showRawView = true;
                }
            }

            TypeDisplayData tdata = GetTypeDisplayData(ctx, type);
            bool            groupPrivateMembers = ctx.Options.GroupPrivateMembers && (ctx.Options.GroupUserPrivateMembers || IsExternalType(ctx, type));

            List <ObjectValue> values           = new List <ObjectValue> ();
            BindingFlags       flattenFlag      = ctx.Options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
            BindingFlags       nonNonPublicFlag = groupPrivateMembers || showRawView ? (BindingFlags)0 : BindingFlags.NonPublic;
            BindingFlags       staticFlag       = ctx.Options.GroupStaticMembers ? (BindingFlags)0 : BindingFlags.Static;
            BindingFlags       access           = BindingFlags.Public | BindingFlags.Instance | flattenFlag | nonNonPublicFlag | staticFlag;

            // Load all members to a list before creating the object values,
            // to avoid problems with objects being invalidated due to evaluations in the target,
            List <ValueReference> list = new List <ValueReference> ();

            list.AddRange(GetMembersSorted(ctx, objectSource, type, proxy, access));

            object tdataType = type;

            foreach (ValueReference val in list)
            {
                try {
                    object decType = val.DeclaringType;
                    if (decType != null && decType != tdataType)
                    {
                        tdataType = decType;
                        tdata     = GetTypeDisplayData(ctx, decType);
                    }
                    DebuggerBrowsableState state = tdata.GetMemberBrowsableState(val.Name);
                    if (state == DebuggerBrowsableState.Never)
                    {
                        continue;
                    }

                    if (state == DebuggerBrowsableState.RootHidden && dereferenceProxy)
                    {
                        object ob = val.Value;
                        if (ob != null)
                        {
                            values.Clear();
                            values.AddRange(GetObjectValueChildren(ctx, val, ob, -1, -1));
                            showRawView = true;
                            break;
                        }
                    }
                    else
                    {
                        ObjectValue oval = val.CreateObjectValue(true);
                        values.Add(oval);
                    }
                }
                catch (Exception ex) {
                    ctx.WriteDebuggerError(ex);
                    values.Add(ObjectValue.CreateError(null, new ObjectPath(val.Name), GetDisplayTypeName(GetTypeName(ctx, val.Type)), ex.Message, val.Flags));
                }
            }

            if (showRawView)
            {
                values.Add(RawViewSource.CreateRawView(ctx, objectSource, obj));
            }
            else
            {
                if (IsArray(ctx, proxy))
                {
                    ICollectionAdaptor col    = CreateArrayAdaptor(ctx, proxy);
                    ArrayElementGroup  agroup = new ArrayElementGroup(ctx, col);
                    ObjectValue        val    = ObjectValue.CreateObject(null, new ObjectPath("Raw View"), "", "", ObjectValueFlags.ReadOnly, values.ToArray());
                    values = new List <ObjectValue> ();
                    values.Add(val);
                    values.AddRange(agroup.GetChildren(ctx.Options));
                }
                else
                {
                    if (ctx.Options.GroupStaticMembers && HasMembers(ctx, type, proxy, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | flattenFlag))
                    {
                        access = BindingFlags.Static | BindingFlags.Public | flattenFlag | nonNonPublicFlag;
                        values.Add(FilteredMembersSource.CreateStaticsNode(ctx, objectSource, type, proxy, access));
                    }
                    if (groupPrivateMembers && HasMembers(ctx, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag))
                    {
                        values.Add(FilteredMembersSource.CreateNonPublicsNode(ctx, objectSource, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag));
                    }

                    if (!ctx.Options.FlattenHierarchy)
                    {
                        object baseType = GetBaseType(ctx, type, false);
                        if (baseType != null)
                        {
                            values.Insert(0, BaseTypeViewSource.CreateBaseTypeView(ctx, objectSource, baseType, proxy));
                        }
                    }
                }
            }
            return(values.ToArray());
        }
コード例 #14
0
        public object GetProxyObject(EvaluationContext ctx, object obj)
        {
            TypeDisplayData data = GetTypeDisplayData (ctx, GetValueType (ctx, obj));
            if (string.IsNullOrEmpty (data.ProxyType) || !ctx.Options.AllowDebuggerProxy)
                return obj;

            string proxyType = data.ProxyType;
            object[] typeArgs = null;

            int index = proxyType.IndexOf ('`');
            if (index != -1) {
                // The proxy type is an uninstantiated generic type.
                // The number of type args of the proxy must match the args of the target object
                int startIndex = index + 1;
                int endIndex = index + 1;

                while (endIndex < proxyType.Length && char.IsDigit (proxyType[endIndex]))
                    endIndex++;

                var attrType = GetType (ctx, "System.Diagnostics.DebuggerTypeProxyAttribute");
                int num = int.Parse (proxyType.Substring (startIndex, endIndex - startIndex));
                var proxiedType = GetBaseTypeWithAttribute (ctx, GetValueType (ctx, obj), attrType);

                if (proxiedType == null || !IsGenericType (ctx, proxiedType))
                    return obj;

                typeArgs = GetTypeArgs (ctx, proxiedType);
                if (typeArgs.Length != num)
                    return obj;

                if (endIndex < proxyType.Length) {
                    // chop off the []'d list of generic type arguments
                    proxyType = proxyType.Substring (0, endIndex);
                }
            }

            object ttype = GetType (ctx, proxyType, typeArgs);
            if (ttype == null) {
                // the proxy type string might be in the form: "Namespace.TypeName, Assembly...", chop off the ", Assembly..." bit.
                if ((index = proxyType.IndexOf (',')) != -1)
                    ttype = GetType (ctx, proxyType.Substring (0, index).Trim (), typeArgs);
            }
            if (ttype == null)
                throw new EvaluatorException ("Unknown type '{0}'", data.ProxyType);

            try {
                object val = CreateValue (ctx, ttype, obj);
                return val ?? obj;
            } catch (EvaluatorException) {
                // probably couldn't find the .ctor for the proxy type because the linker stripped it out
                return obj;
            } catch (Exception ex) {
                ctx.WriteDebuggerError (ex);
                return obj;
            }
        }
コード例 #15
0
        public virtual CompletionData GetExpressionCompletionData(EvaluationContext ctx, string expr)
        {
            if (string.IsNullOrEmpty (expr))
                return null;

            if (expr[expr.Length - 1] == '.') {
                try {
                    var vr = ctx.Evaluator.Evaluate (ctx, expr.Substring (0, expr.Length - 1), null);
                    if (vr != null)
                        return GetMemberCompletionData (ctx, vr);

                    // FIXME: handle types and namespaces...
                } catch (Exception ex) {
                    ctx.WriteDebuggerError (ex);
                }

                return null;
            }

            bool lastWastLetter = false;
            int i = expr.Length - 1;

            while (i >= 0) {
                char c = expr[i--];
                if (!char.IsLetterOrDigit (c) && c != '_')
                    break;

                lastWastLetter = !char.IsDigit (c);
            }

            if (lastWastLetter) {
                string partialWord = expr.Substring (i+1);

                CompletionData data = new CompletionData ();
                data.ExpressionLength = partialWord.Length;

                // Local variables

                foreach (ValueReference vc in GetLocalVariables (ctx))
                    if (vc.Name.StartsWith (partialWord, StringComparison.InvariantCulture))
                        data.Items.Add (new CompletionItem (vc.Name, vc.Flags));

                // Parameters

                foreach (ValueReference vc in GetParameters (ctx))
                    if (vc.Name.StartsWith (partialWord, StringComparison.InvariantCulture))
                        data.Items.Add (new CompletionItem (vc.Name, vc.Flags));

                // Members

                ValueReference thisobj = GetThisReference (ctx);

                if (thisobj != null)
                    data.Items.Add (new CompletionItem ("this", ObjectValueFlags.Field | ObjectValueFlags.ReadOnly));

                object type = GetEnclosingType (ctx);

                foreach (ValueReference vc in GetMembers (ctx, null, type, thisobj != null ? thisobj.Value : null))
                    if (vc.Name.StartsWith (partialWord, StringComparison.InvariantCulture))
                        data.Items.Add (new CompletionItem (vc.Name, vc.Flags));

                if (data.Items.Count > 0)
                    return data;
            }

            return null;
        }