Пример #1
0
        public void Constructor_Type()
        {
            var dtp = new DebuggerTypeProxyAttribute(typeof(string));

            Assert.IsNull(dtp.Target, "#1");
            Assert.AreEqual(typeof(string).AssemblyQualifiedName, dtp.ProxyTypeName, "#2");
        }
        private static void TestDebuggerTypeProxyProperties(object obj)
        {
#if NET_4_0_ABOVE
            var attrs = obj.GetType().GetTypeInfo().GetCustomAttributes(typeof(DebuggerTypeProxyAttribute), false).ToArray();
#else
            var attrs = obj.GetType().GetCustomAttributes(typeof(DebuggerTypeProxyAttribute), false).ToArray();
#endif
            Assert.Equal(expected: 1, actual: attrs.Length);

            DebuggerTypeProxyAttribute dtpa = (DebuggerTypeProxyAttribute)attrs[0];
            string attrText         = dtpa.ProxyTypeName;
            var    proxyType        = Type.GetType(attrText);
            var    genericArguments = obj.GetType().GetGenericArguments();
            if (genericArguments.Any())
            {
                proxyType = proxyType.MakeGenericType(genericArguments);
            }
            object proxyInstance = Activator.CreateInstance(proxyType, obj);             // make sure we can instantiate it

            PropertyInfo[] propertyInfos = proxyInstance.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (var pi in propertyInfos)
            {
                pi.GetValue(proxyInstance, null);                 // make sure we can access all its properties
            }
        }
        public void Ctor_Type(Type type)
        {
            var attribute = new DebuggerTypeProxyAttribute(type);

            Assert.Equal(type.AssemblyQualifiedName, attribute.ProxyTypeName);
            Assert.Null(attribute.Target);
            Assert.Null(attribute.TargetTypeName);
        }
        public void Ctor_TypeName(string typeName)
        {
            var attribute = new DebuggerTypeProxyAttribute(typeName);

            Assert.Equal(typeName, attribute.ProxyTypeName);
            Assert.Null(attribute.Target);
            Assert.Null(attribute.TargetTypeName);
        }
        public void TargetTypeName_Set_GetReturnsExpected(string targetTypeName)
        {
            var attribute = new DebuggerTypeProxyAttribute("TypeName")
            {
                TargetTypeName = targetTypeName
            };

            Assert.Equal(targetTypeName, attribute.TargetTypeName);
        }
        public void Target_Set_GetReturnsExpected(Type target)
        {
            var attribute = new DebuggerTypeProxyAttribute("TypeName")
            {
                Target = target
            };

            Assert.Equal(target, attribute.Target);
            Assert.Equal(target.AssemblyQualifiedName, attribute.TargetTypeName);
        }
Пример #7
0
        private static bool AllDebuggerTypeProxyPropertiesWork(object obj)
        {
            var attrs = obj.GetType().GetCustomAttributes(typeof(DebuggerTypeProxyAttribute), false);

            if (attrs.Length != 1)
            {
                Console.WriteLine("Incorrect number of DebuggerTypeProxyAttributes");
                return(false);
            }

            object proxyInstance = null;

            try
            {
                DebuggerTypeProxyAttribute dtpa = (DebuggerTypeProxyAttribute)attrs[0];
                string attrText         = dtpa.ProxyTypeName;
                var    proxyType        = Type.GetType(attrText);
                var    genericArguments = obj.GetType().GetGenericArguments();
                if (genericArguments.Any())
                {
                    proxyType = proxyType.MakeGenericType(genericArguments);
                }
                proxyInstance = Activator.CreateInstance(proxyType, obj);
            }
            catch (Exception) { }
            if (proxyInstance == null)
            {
                Console.WriteLine("Could not instantiate proxy");
                return(false);
            }

            bool success = true;

            try
            {
                var propertyInfos = proxyInstance.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                foreach (var pi in propertyInfos)
                {
                    object result = pi.GetValue(proxyInstance, null);
                }
            }
            catch { success = false; }
            if (!success)
            {
                Console.WriteLine("Could not invoke all proxy properties");
                return(false);
            }

            return(success);
        }
Пример #8
0
        void DebuggerTypeProxyAttributePropertiesRoundTrip()
        {
            DebuggerTypeProxyAttribute d = new DebuggerTypeProxyAttribute(typeof(DebugTests));

            d.Target = typeof(AttributeTests);
            Assert.Equal(typeof(AttributeTests), d.Target);
            Assert.Equal(typeof(AttributeTests).AssemblyQualifiedName, d.TargetTypeName);

            Assert.Throws <ArgumentNullException>(() => d.Target = null);

            d.TargetTypeName = typeof(DebugTests).AssemblyQualifiedName;
            Assert.Equal(typeof(DebugTests).AssemblyQualifiedName, d.TargetTypeName);
            Assert.Equal(typeof(AttributeTests), d.Target);
        }
Пример #9
0
        void DebuggerTypeProxyAttributePropertiesRoundTrip()
        {
            DebuggerTypeProxyAttribute d = new DebuggerTypeProxyAttribute(typeof(DebugTests));

            d.Target = typeof(AttributeTests);
            Assert.Equal(typeof(AttributeTests), d.Target);
            Assert.Equal(typeof(AttributeTests).AssemblyQualifiedName, d.TargetTypeName);

            Assert.Throws<ArgumentNullException>(() => d.Target = null);

            d.TargetTypeName = typeof(DebugTests).AssemblyQualifiedName;
            Assert.Equal(typeof(DebugTests).AssemblyQualifiedName, d.TargetTypeName);
            Assert.Equal(typeof(AttributeTests), d.Target);
        }
Пример #10
0
        protected override TypeDisplayData OnGetTypeDisplayData(EvaluationContext ctx, object gtype)
        {
            CorType type = (CorType)gtype;

            CorEvaluationContext wctx = (CorEvaluationContext)ctx;
            Type t = type.GetTypeInfo(wctx.Session);

            if (t == null)
            {
                return(null);
            }

            string proxyType          = null;
            string nameDisplayString  = null;
            string typeDisplayString  = null;
            string valueDisplayString = null;
            Dictionary <string, DebuggerBrowsableState> memberData = null;
            bool hasTypeData = false;

            foreach (object att in t.GetCustomAttributes(false))
            {
                DebuggerTypeProxyAttribute patt = att as DebuggerTypeProxyAttribute;
                if (patt != null)
                {
                    proxyType   = patt.ProxyTypeName;
                    hasTypeData = true;
                    continue;
                }
                DebuggerDisplayAttribute datt = att as DebuggerDisplayAttribute;
                if (datt != null)
                {
                    hasTypeData        = true;
                    nameDisplayString  = datt.Name;
                    typeDisplayString  = datt.Type;
                    valueDisplayString = datt.Value;
                    continue;
                }
            }

            ArrayList mems = new ArrayList();

            mems.AddRange(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance));
            mems.AddRange(t.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance));

            foreach (MemberInfo m in mems)
            {
                object[] atts = m.GetCustomAttributes(typeof(DebuggerBrowsableAttribute), false);
                if (atts.Length == 0)
                {
                    atts = m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false);
                    if (atts.Length > 0)
                    {
                        atts[0] = new DebuggerBrowsableAttribute(DebuggerBrowsableState.Never);
                    }
                }
                if (atts.Length > 0)
                {
                    hasTypeData = true;
                    if (memberData == null)
                    {
                        memberData = new Dictionary <string, DebuggerBrowsableState> ();
                    }
                    memberData[m.Name] = ((DebuggerBrowsableAttribute)atts[0]).State;
                }
            }
            if (hasTypeData)
            {
                return(new TypeDisplayData(proxyType, valueDisplayString, typeDisplayString, nameDisplayString, false, memberData));
            }
            else
            {
                return(null);
            }
        }
        public void Target_SetNull_ThrowsArgumentNullException()
        {
            var attribute = new DebuggerTypeProxyAttribute("TypeName");

            AssertExtensions.Throws <ArgumentNullException>("value", () => attribute.Target = null);
        }
        protected override TypeDisplayData OnGetTypeDisplayData(EvaluationContext gctx, object type)
        {
            SoftEvaluationContext ctx = (SoftEvaluationContext)gctx;
            TypeDisplayData       td  = new TypeDisplayData();

            try {
                TypeMirror t = (TypeMirror)type;
                foreach (CustomAttributeDataMirror attr in t.GetCustomAttributes(true))
                {
                    string attName = attr.Constructor.DeclaringType.FullName;
                    if (attName == "System.Diagnostics.DebuggerDisplayAttribute")
                    {
                        DebuggerDisplayAttribute at = BuildAttribute <DebuggerDisplayAttribute> (attr);
                        td.NameDisplayString  = at.Name;
                        td.TypeDisplayString  = at.Type;
                        td.ValueDisplayString = at.Value;
                    }
                    else if (attName == "System.Diagnostics.DebuggerTypeProxyAttribute")
                    {
                        DebuggerTypeProxyAttribute at = BuildAttribute <DebuggerTypeProxyAttribute> (attr);
                        td.ProxyType = at.ProxyTypeName;
                        if (!string.IsNullOrEmpty(td.ProxyType))
                        {
                            ForceLoadType(ctx, td.ProxyType);
                        }
                    }
                }
                foreach (FieldInfoMirror fi in t.GetFields())
                {
                    CustomAttributeDataMirror[] attrs = fi.GetCustomAttributes(true);
                    DebuggerBrowsableAttribute  att   = GetAttribute <DebuggerBrowsableAttribute> (attrs);
                    if (att == null)
                    {
                        var cga = GetAttribute <System.Runtime.CompilerServices.CompilerGeneratedAttribute> (attrs);
                        if (cga != null)
                        {
                            att = new DebuggerBrowsableAttribute(DebuggerBrowsableState.Never);
                        }
                    }
                    if (att != null)
                    {
                        if (td.MemberData == null)
                        {
                            td.MemberData = new Dictionary <string, DebuggerBrowsableState> ();
                        }
                        td.MemberData [fi.Name] = att.State;
                    }
                }
                foreach (PropertyInfoMirror pi in t.GetProperties())
                {
                    DebuggerBrowsableAttribute att = GetAttribute <DebuggerBrowsableAttribute> (pi.GetCustomAttributes(true));
                    if (att != null)
                    {
                        if (td.MemberData == null)
                        {
                            td.MemberData = new Dictionary <string, DebuggerBrowsableState> ();
                        }
                        td.MemberData [pi.Name] = att.State;
                    }
                }
            } catch (Exception ex) {
                ctx.Session.WriteDebuggerOutput(true, ex.ToString());
            }
            return(td);
        }
Пример #13
0
        public BlockWatcher(object block, string name)
        {
            EventHandler       handler  = null;
            RoutedEventHandler handler2 = null;
            RoutedEventHandler handler3 = null;

            this._blockWidth = 20.0;
            StackPanel panel = new StackPanel {
                Orientation = Orientation.Horizontal
            };

            this._blocksPanel = panel;
            ToggleButton button = new ToggleButton();
            TextBlock    block2 = new TextBlock {
                Text              = "A",
                FontWeight        = FontWeights.Bold,
                Margin            = new Thickness(2.0, 0.0, 1.5, 0.0),
                VerticalAlignment = VerticalAlignment.Center
            };

            button.Content           = block2;
            button.IsChecked         = false;
            button.Margin            = new Thickness(1.0, 0.0, 5.0, 0.0);
            button.VerticalAlignment = VerticalAlignment.Stretch;
            button.Cursor            = Cursors.Hand;
            button.ToolTip           = "Show message content";
            button.Visibility        = Visibility.Collapsed;
            this._chkDetail          = button;
            TextBlock block3 = new TextBlock {
                Text              = "\x00d5",
                FontSize          = 20.0,
                FontWeight        = FontWeights.Bold,
                Foreground        = Brushes.DarkRed,
                Visibility        = Visibility.Collapsed,
                VerticalAlignment = VerticalAlignment.Center,
                Margin            = new Thickness(0.0, 0.0, 3.0, 0.0),
                ToolTip           = "Block is permanently declining messages"
            };

            this._txtDeclining = block3;
            TextBlock block4 = new TextBlock {
                VerticalAlignment = VerticalAlignment.Center,
                ToolTip           = "Postedponed Messages",
                Foreground        = Brushes.Blue
            };

            this._txtPostPoned = block4;
            Action <Task> continuationAction = null;

            this._block = block;
            try
            {
                this._txtPostPoned.FontFamily = new FontFamily("Verdana");
            }
            catch
            {
            }
            try
            {
                this._txtDeclining.FontFamily = new FontFamily("WingDings");
            }
            catch
            {
            }
            Type type = block.GetType();

            this._iDataFlowBlockType = type.GetInterface("IDataflowBlock");
            if (type.IsGenericType)
            {
                Type[] genericArguments = type.GetGenericArguments();
                if (((genericArguments.Length <= 2) && this.ShouldExpandType(genericArguments.First <Type>())) && this.ShouldExpandType(genericArguments.Last <Type>()))
                {
                    this._chkDetail.IsChecked = true;
                }
            }
            DebuggerTypeProxyAttribute attribute = (DebuggerTypeProxyAttribute)block.GetType().GetCustomAttributes(typeof(DebuggerTypeProxyAttribute), true).FirstOrDefault <object>();

            if (attribute == null)
            {
                throw new InvalidOperationException("Object has no DebuggerTypeProxyAttribute");
            }
            Type type3 = Type.GetType(attribute.ProxyTypeName).MakeGenericType(block.GetType().GetGenericArguments());

            this._proxy         = Activator.CreateInstance(type3, new object[] { block });
            this._exeProp       = type3.GetProperty("CurrentDegreeOfParallelism");
            this._inputProp     = type3.GetProperty("InputQueue");
            this._outputProp    = type3.GetProperty("OutputQueue");
            this._postponedProp = type3.GetProperty("PostponedMessages");
            if ((this._inputProp == null) && (this._outputProp == null))
            {
                this._outputProp = type3.GetProperty("Queue");
            }
            if (this._outputProp == null)
            {
                this._outputCountProp = type3.GetProperty("OutputCount");
            }
            this._hasValueProp  = type3.GetProperty("HasValue");
            this._valueProp     = type3.GetProperty("Value");
            this._decliningProp = type3.GetProperty("IsDecliningPermanently");
            StackPanel panel3 = new StackPanel {
                Orientation = Orientation.Horizontal
            };

            if ((this._txtDeclining.FontFamily.FamilyNames != null) && (this._txtDeclining.FontFamily.FamilyNames.Count > 0))
            {
            }
            if ((CS$ < > 9__CachedAnonymousMethodDelegate10 == null) && this._txtDeclining.FontFamily.FamilyNames.Any <KeyValuePair <XmlLanguage, string> >(CS$ < > 9__CachedAnonymousMethodDelegate10))
            {
                panel3.Children.Add(this._txtDeclining);
            }
            panel3.Children.Add(this._chkDetail);
            panel3.Children.Add(this._txtPostPoned);
            panel3.Children.Add(this._blocksPanel);
            GroupBox  box    = new GroupBox();
            TextBlock block5 = new TextBlock {
                Text       = name,
                FontWeight = FontWeights.SemiBold
            };

            box.Header              = block5;
            box.BorderThickness     = new Thickness(2.0);
            box.BorderBrush         = Brushes.LightSkyBlue;
            box.Content             = panel3;
            box.Margin              = new Thickness(0.0, 0.0, 5.0, 0.0);
            box.HorizontalAlignment = HorizontalAlignment.Left;
            GroupBox groupBox = box;
            Border   border2  = new Border {
                Child = groupBox,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            base.Content = this._mainPanel = border2;
            DispatcherTimer timer2 = new DispatcherTimer(DispatcherPriority.Normal, base.Dispatcher)
            {
                Interval  = TimeSpan.FromMilliseconds(100.0),
                IsEnabled = true
            };

            if (handler == null)
            {
                handler = (sender, e) => this.UpdateBlocksPanel();
            }
            timer2.Tick += handler;
            PropertyInfo property = this._iDataFlowBlockType.GetProperty("Completion");

            if (property != null)
            {
                Task task = property.GetValue(this._block, null) as Task;
                if (task != null)
                {
                    if (continuationAction == null)
                    {
                        continuationAction = delegate(Task ant) {
                            try
                            {
                                bool   faulted = ant.IsFaulted;
                                string msg     = faulted ? (ant.Exception.InnerException.GetType().Name + ": " + ant.Exception.InnerException.Message + " ") : null;
                                Action method  = delegate {
                                    try
                                    {
                                        if (faulted)
                                        {
                                            groupBox.BorderBrush = Brushes.Red;
                                        }
                                        this._txtDeclining.Text       = "\x00fc";
                                        this._txtDeclining.ToolTip    = "Block has completed";
                                        this._txtDeclining.Foreground = Brushes.Green;
                                        this._txtDeclining.Visibility = Visibility.Visible;
                                        if (faulted)
                                        {
                                            groupBox.Content = msg;
                                        }
                                    }
                                    catch
                                    {
                                    }
                                };
                                groupBox.Dispatcher.BeginInvoke(method, new object[0]);
                            }
                            catch
                            {
                            }
                        };
                    }
                    task.ContinueWith(continuationAction);
                }
            }
            if (handler2 == null)
            {
                handler2 = (sender, e) => this._lastExeCount = -1;
            }
            this._chkDetail.Checked += handler2;
            if (handler3 == null)
            {
                handler3 = (sender, e) => this._lastExeCount = -1;
            }
            this._chkDetail.Unchecked += handler3;
        }