public void TargetTest ()
		{
			DebuggerDisplayAttribute dda;

			dda = new DebuggerDisplayAttribute (null);
			Assert.AreEqual (string.Empty, dda.Value, "A1");
			Assert.IsNull (dda.Target, "A2");
			Assert.IsNull (dda.TargetTypeName, "A3");
			Assert.AreEqual (string.Empty, dda.Type, "A4");
			Assert.AreEqual (string.Empty, dda.Name, "A4");

			dda.Target = typeof(string);
			Assert.AreEqual (string.Empty, dda.Value, "B1");
			Assert.IsNotNull (dda.Target, "B2");
			Assert.AreSame (typeof(string), dda.Target, "B2-b");
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, dda.TargetTypeName, "B3");
			Assert.AreEqual (string.Empty, dda.Type, "B4");
			Assert.AreEqual (string.Empty, dda.Name, "B4");

			try {
				dda.Target = null;
				Assert.Fail ("Excepted ArgumentNullException, got no exception.");
			} catch (ArgumentNullException) {
			}
		}
		public void TargetTypeNameTest ()
		{
			DebuggerDisplayAttribute dda;

			dda = new DebuggerDisplayAttribute (null);
			Assert.AreEqual (string.Empty, dda.Value, "A1");
			Assert.IsNull (dda.Target, "A2");
			Assert.IsNull (dda.TargetTypeName, "A3");
			Assert.AreEqual (string.Empty, dda.Type, "A4");
			Assert.AreEqual (string.Empty, dda.Name, "A4");

			dda.TargetTypeName = "System.String";
			Assert.AreEqual (string.Empty, dda.Value, "B1");
			Assert.IsNull (dda.Target, "B2");
			Assert.AreEqual ("System.String", dda.TargetTypeName, "B3");
			Assert.AreEqual (string.Empty, dda.Type, "B4");
			Assert.AreEqual (string.Empty, dda.Name, "B4");

			dda.TargetTypeName = null;
			Assert.AreEqual (string.Empty, dda.Value, "C1");
			Assert.IsNull (dda.Target, "C2");
			Assert.IsNull (dda.TargetTypeName, "C3");
			Assert.AreEqual (string.Empty, dda.Type, "C4");
			Assert.AreEqual (string.Empty, dda.Name, "C4");

			dda.TargetTypeName = string.Empty;
			Assert.AreEqual (string.Empty, dda.Value, "D1");
			Assert.IsNull (dda.Target, "D2");
			Assert.AreEqual (string.Empty, dda.TargetTypeName, "D3");
			Assert.AreEqual (string.Empty, dda.Type, "D4");
			Assert.AreEqual (string.Empty, dda.Name, "D4");
		}
		public void ConstructorTest ()
		{
			DebuggerDisplayAttribute dda;

			dda = new DebuggerDisplayAttribute (null);
			Assert.AreEqual (string.Empty, dda.Value, "A1");
			Assert.IsNull (dda.Target, "A2");
			Assert.IsNull (dda.TargetTypeName, "A3");
			Assert.AreEqual (string.Empty, dda.Type, "A4");
			Assert.AreEqual (string.Empty, dda.Name, "A4");

			dda = new DebuggerDisplayAttribute ("abc");
			Assert.AreEqual ("abc", dda.Value, "B1");
			Assert.IsNull (dda.Target, "B2");
			Assert.IsNull (dda.TargetTypeName, "B3");
			Assert.AreEqual (string.Empty, dda.Type, "B4");
			Assert.AreEqual (string.Empty, dda.Name, "B4");
		}
Exemple #4
0
        public static EE.EvaluationResult HandleDebuggerDisplay(Interpreter interpreter,
									 Thread thread,
									 TargetStructObject instance,
									 DebuggerDisplayAttribute attr,
									 int timeout, out string name,
									 out string type)
        {
            ScriptingContext expr_context = new ScriptingContext (interpreter);
            expr_context.CurrentThread = thread;
            expr_context.CurrentLanguage = instance.Type.Language;
            expr_context.ImplicitInstance = instance;

            EE.EvaluationResult result = expr_context.HandleDebuggerDisplay (
                 thread, instance, attr.Value, timeout, out name);

            if (result != EE.EvaluationResult.Ok) {
                type = null;
                return result;
            }

            if (String.IsNullOrEmpty (attr.Type)) {
                type = null;
                return EE.EvaluationResult.Ok;
            }

            return expr_context.HandleDebuggerDisplay (
                thread, instance, attr.Type, timeout, out type);
        }
        internal static void CheckCustomAttributes(Cecil.ICustomAttributeProvider type,
							    out DebuggerBrowsableState? browsable_state,
							    out DebuggerDisplayAttribute debugger_display,
							    out DebuggerTypeProxyAttribute type_proxy,
							    out bool is_compiler_generated)
        {
            browsable_state = null;
            debugger_display = null;
            type_proxy = null;
            is_compiler_generated = false;

            foreach (Cecil.CustomAttribute cattr in type.CustomAttributes) {
                string cname = cattr.Constructor.DeclaringType.FullName;
                if (cname == cgen_attr) {
                    is_compiler_generated = true;
                } else if (cname == debugger_display_attr) {
                    string text = (string) cattr.ConstructorArguments [0].Value;
                    debugger_display = new DebuggerDisplayAttribute (text);
                    foreach (var named_arg in cattr.Properties) {
                        string key = named_arg.Name;
                        if (key == "Name")
                            debugger_display.Name = (string) named_arg.Argument.Value;
                        else if (key == "Type")
                            debugger_display.Type = (string) named_arg.Argument.Value;
                        else {
                            debugger_display = null;
                            break;
                        }
                    }
                } else if (cname == browsable_attr) {
                    browsable_state = (DebuggerBrowsableState) cattr.GetBlob () [2];
                } else if (cname == type_proxy_attr) {
                    string text = (string) cattr.ConstructorArguments [0].Value;
                    type_proxy = new DebuggerTypeProxyAttribute (text);
                }
            }
        }