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)
5
using System.Collections.Generic;
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;
14
namespace Debugger.AddIn.Visualizers.GridVisualizer
17
/// Provides <see cref="ObjectValue"/>s for debugee objects implementing IList.
19
public class ListValuesProvider : GridValuesProvider, IListValuesProvider<ObjectValue>
21
int? listCount = null;
23
/// After evaluating how many items to clear debugger Expression cache,
24
/// so that the cache does not keep too many PermanentReferences.
26
static readonly int ClearCacheThreshold = 50;
28
public ListValuesProvider(Expression targetObject, DebugType listItemType)
29
:base(targetObject, listItemType)
35
if (this.listCount == null) {
36
this.listCount = this.targetObject.GetIListCount();
38
return this.listCount.Value;
41
/// <summary>When this reaches ClearCacheThreshold, the debugger Expression cache is cleared.</summary>
42
int itemClearCacheCounter = 0;
44
public ObjectValue GetItemAt(int index)
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;
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
56
this.memberFromNameMap);