~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Debugger/Debugger.AddIn/Visualizers/GridVisualizer/ValueProviders/ListValuesProvider.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Linq;
 
7
using System.Reflection;
 
8
using Debugger.AddIn.Visualizers.Utils;
 
9
using Debugger.MetaData;
 
10
using ICSharpCode.Core;
 
11
using ICSharpCode.NRefactory.Ast;
 
12
using ICSharpCode.SharpDevelop.Services;
 
13
 
 
14
namespace Debugger.AddIn.Visualizers.GridVisualizer
 
15
{
 
16
        /// <summary>
 
17
        ///  Provides <see cref="ObjectValue"/>s for debugee objects implementing IList.
 
18
        /// </summary>
 
19
        public class ListValuesProvider : GridValuesProvider, IListValuesProvider<ObjectValue>
 
20
        {
 
21
                int? listCount = null;
 
22
                /// <summary>
 
23
                /// After evaluating how many items to clear debugger Expression cache,
 
24
                /// so that the cache does not keep too many PermanentReferences.
 
25
                /// </summary>
 
26
                static readonly int ClearCacheThreshold = 50;
 
27
                
 
28
                public ListValuesProvider(Expression targetObject, DebugType listItemType)
 
29
                        :base(targetObject, listItemType)
 
30
                {
 
31
                }
 
32
                
 
33
                public int GetCount()
 
34
                {
 
35
                        if (this.listCount == null) {
 
36
                                this.listCount = this.targetObject.GetIListCount();
 
37
                        }
 
38
                        return this.listCount.Value;
 
39
                }
 
40
                
 
41
                /// <summary>When this reaches ClearCacheThreshold, the debugger Expression cache is cleared.</summary>
 
42
                int itemClearCacheCounter = 0;
 
43
                
 
44
                public ObjectValue GetItemAt(int index)
 
45
                {
 
46
                        if (itemClearCacheCounter++ > ClearCacheThreshold) {
 
47
                                // clear debugger Expression cache to avoid holding too many PermanentReferences
 
48
                                WindowsDebugger.CurrentProcess.ClearExpressionCache();
 
49
                                LoggingService.Info("Cleared debugger Expression cache.");
 
50
                                itemClearCacheCounter = 0;
 
51
                        }
 
52
                        return ObjectValue.Create(
 
53
                                targetObject.AppendIndexer(index).Evaluate(WindowsDebugger.CurrentProcess),
 
54
                                //targetObject.AppendIndexer(index), // use Expression instead of value - possible only for IList though
 
55
                                index,
 
56
                                this.memberFromNameMap);
 
57
                }
 
58
        }
 
59
}