Example #1
0
        private VisualizerInfo Scan(TypeName name, IVariableInformation variable)
        {
            int aliasChain = 0;

tryAgain:
            foreach (var autoVis in _typeVisualizers)
            {
                var visualizer = autoVis.Visualizers.Find((v) => v.ParsedName.Match(name));   // TODO: match on View, version, etc
                if (visualizer != null)
                {
                    _vizCache[variable.TypeName] = new VisualizerInfo(visualizer.Visualizer, name);
                    return(_vizCache[variable.TypeName]);
                }
            }
            // failed to find a visualizer for the type, try looking for a typedef
            foreach (var autoVis in _typeVisualizers)
            {
                var alias = autoVis.Aliases.Find((v) => v.ParsedName.Match(name));   // TODO: match on View, version, etc
                if (alias != null)
                {
                    // add the template parameter macro values
                    var scopedNames = new Dictionary <string, string>();
                    int t           = 1;
                    for (int i = 0; i < name.Qualifiers.Count; ++i)
                    {
                        for (int j = 0; j < name.Qualifiers[i].Args.Count; ++j)
                        {
                            scopedNames["$T" + t] = name.Qualifiers[i].Args[j].FullyQualifiedName;
                            t++;
                        }
                    }

                    string newName = ReplaceNamesInExpression(alias.Alias.Value, null, scopedNames);
                    name = TypeName.Parse(newName);
                    aliasChain++;
                    if (aliasChain > MAX_ALIAS_CHAIN)
                    {
                        break;
                    }
                    goto tryAgain;
                }
            }
            return(null);
        }
Example #2
0
        private bool LoadFile(string path)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AutoVisualizer));
                if (!File.Exists(path))
                {
                    _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.FileNotFound, path));
                    return(false);
                }
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;
                settings.XmlResolver = null;

                using (var stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(stream, settings))
                    {
                        AutoVisualizer autoVis = null;
                        autoVis = serializer.Deserialize(reader) as AutoVisualizer;
                        if (autoVis != null)
                        {
                            FileInfo f = new FileInfo(autoVis);
                            if (autoVis.Items == null)
                            {
                                return(false);
                            }
                            foreach (var o in autoVis.Items)
                            {
                                if (o is VisualizerType)
                                {
                                    VisualizerType v = (VisualizerType)o;
                                    TypeName       t = TypeName.Parse(v.Name);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Visualizers.Add(new TypeInfo(t, v));
                                        }
                                    }
                                    // add an entry for each alternative name too
                                    if (v.AlternativeType != null)
                                    {
                                        foreach (var a in v.AlternativeType)
                                        {
                                            t = TypeName.Parse(a.Name);
                                            if (t != null)
                                            {
                                                lock (_typeVisualizers)
                                                {
                                                    f.Visualizers.Add(new TypeInfo(t, v));
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (o is AliasType)
                                {
                                    AliasType a = (AliasType)o;
                                    TypeName  t = TypeName.Parse(a.Name);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Aliases.Add(new AliasInfo(t, a));
                                        }
                                    }
                                }
                            }
                            _typeVisualizers.Add(f);
                        }
                        return(autoVis != null);
                    }
            }
            catch (Exception exception)
            {
                // don't allow natvis failures to stop debugging
                _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.ErrorReadingFile, exception.Message, path));
                return(false);
            }
        }
Example #3
0
        private bool LoadFile(string path)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AutoVisualizer));
                if (!File.Exists(path))
                {
                    _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.FileNotFound, path));
                    return(false);
                }
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;

                // set XmlResolver via reflection, if it exists. This is required for desktop CLR, as otherwise the XML reader may
                // attempt to hit untrusted external resources.
                var xmlResolverProperty = settings.GetType().GetProperty("XmlResolver", BindingFlags.Public | BindingFlags.Instance);
                xmlResolverProperty?.SetValue(settings, null);

                using (var stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(stream, settings))
                    {
                        AutoVisualizer autoVis = null;
                        autoVis = serializer.Deserialize(reader) as AutoVisualizer;
                        if (autoVis != null)
                        {
                            FileInfo f = new FileInfo(autoVis);
                            if (autoVis.Items == null)
                            {
                                return(false);
                            }
                            foreach (var o in autoVis.Items)
                            {
                                if (o is VisualizerType)
                                {
                                    VisualizerType v = (VisualizerType)o;
                                    TypeName       t = TypeName.Parse(v.Name, _process.Logger);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Visualizers.Add(new TypeInfo(t, v));
                                        }
                                    }
                                    // add an entry for each alternative name too
                                    if (v.AlternativeType != null)
                                    {
                                        foreach (var a in v.AlternativeType)
                                        {
                                            t = TypeName.Parse(a.Name, _process.Logger);
                                            if (t != null)
                                            {
                                                lock (_typeVisualizers)
                                                {
                                                    f.Visualizers.Add(new TypeInfo(t, v));
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (o is AliasType)
                                {
                                    AliasType a = (AliasType)o;
                                    TypeName  t = TypeName.Parse(a.Name, _process.Logger);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Aliases.Add(new AliasInfo(t, a));
                                        }
                                    }
                                }
                            }
                            _typeVisualizers.Add(f);
                        }
                        return(autoVis != null);
                    }
            }
            catch (Exception exception)
            {
                // don't allow natvis failures to stop debugging
                _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.ErrorReadingFile, exception.Message, path));
                return(false);
            }
        }