Browse Source

DependencyMatrix now calculates some of values.

pull/19/head
Tomas Linhart 15 years ago
parent
commit
98d36e1175
  1. 10
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 2
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.sln
  3. 7
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs
  4. 3
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs
  5. 40
      src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs
  6. 3
      src/AddIns/Analysis/CodeQuality/Src/Controls/TreeMatrixControl.xaml.cs
  7. 15
      src/AddIns/Analysis/CodeQuality/Src/IValue.cs
  8. 12
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  9. 10
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs
  10. 51
      src/AddIns/Analysis/CodeQuality/Src/Namespace.cs
  11. 18
      src/AddIns/Analysis/CodeQuality/Src/Relationship.cs
  12. 138
      src/AddIns/Analysis/CodeQuality/Src/Utility/DoubleKeyDictionary.cs
  13. 61
      src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs

10
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj

@ -120,17 +120,17 @@ @@ -120,17 +120,17 @@
<Compile Include="Src\Controls\DependencyMatrix.cs" />
<Compile Include="Src\Controls\DependencyVertex.cs" />
<Compile Include="Src\Controls\DependencyIconVertexConverter.cs" />
<Compile Include="Src\Controls\Matrix.cs" />
<Compile Include="Src\Controls\MatrixControl.cs" />
<Compile Include="Src\Controls\TreeMatrixControl.xaml.cs">
<DependentUpon>TreeMatrixControl.xaml</DependentUpon>
<SubType>Code</SubType>
<DependentUpon>TreeMatrixControl.xaml</DependentUpon>
</Compile>
<Compile Include="Src\DependencyGraphCommand.cs" />
<Compile Include="Src\Event.cs" />
<Compile Include="Src\Field.cs" />
<Compile Include="Src\INode.cs" />
<Compile Include="Src\Instruction.cs" />
<Compile Include="Src\IValue.cs" />
<Compile Include="Src\NodeIconService.cs" />
<Compile Include="Src\IDependency.cs" />
<Compile Include="Src\MetricsReader.cs" />
@ -139,6 +139,8 @@ @@ -139,6 +139,8 @@
<Compile Include="Src\Relationship.cs" />
<Compile Include="Src\RelationshipType.cs" />
<Compile Include="Src\Type.cs" />
<Compile Include="Src\Utility\DoubleKeyDictionary.cs" />
<Compile Include="Src\Utility\Matrix.cs" />
<Page Include="Resources\GraphTemplate.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -243,7 +245,9 @@ @@ -243,7 +245,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Src\Utility" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

2
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.sln

@ -73,7 +73,7 @@ Global @@ -73,7 +73,7 @@ Global
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Release|x86.Build.0 = Release|Any CPU
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Release|x86.ActiveCfg = Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.Build.0 = net_2_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.ActiveCfg = net_2_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.Build.0 = net_2_0_Debug|Any CPU

7
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs

@ -5,14 +5,15 @@ using System; @@ -5,14 +5,15 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.CodeQualityAnalysis.Utility;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyMatrix : Matrix<INode>
public class DependencyMatrix : Matrix<INode, Relationship>
{
public override object EvaluateCell(MatrixCell<INode> rowHeader, MatrixCell<INode> columnHeader)
protected override Relationship GetCellValue(int rowIndex, int columnIndex)
{
return rowHeader.Value.GetRelationship(columnHeader.Value);
return HeaderRows[rowIndex].Value.GetRelationship(HeaderColumns[columnIndex].Value);
}
}
}

3
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs

@ -11,7 +11,8 @@ using System.Windows.Controls.Primitives; @@ -11,7 +11,8 @@ using System.Windows.Controls.Primitives;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyMatrixControl : MatrixControl<INode>
public class DependencyMatrixControl : MatrixControl<INode, Relationship>
{
}
}

40
src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using ICSharpCode.CodeQualityAnalysis.Utility;
using System.Drawing.Drawing2D;
using System.Windows;
using System.Windows.Controls;
@ -12,7 +13,8 @@ using System.Windows.Media.Imaging; @@ -12,7 +13,8 @@ using System.Windows.Media.Imaging;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class MatrixControl<TValue> : FrameworkElement, IScrollInfo
public class MatrixControl<TItem, TValue> : FrameworkElement, IScrollInfo
where TValue : IValue
{
private Dictionary<string, ImageSource> imgs = new Dictionary<string, ImageSource>();
private Coords currentCell = new Coords(-1, -1);
@ -28,17 +30,17 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls @@ -28,17 +30,17 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
private int matrixWidth = 0;
private int matrixHeight = 0;
private Matrix<TValue> matrix;
private Matrix<TItem, TValue> matrix;
public Matrix<TValue> Matrix
public Matrix<TItem, TValue> Matrix
{
get { return matrix; }
set
{
matrix = value;
matrixHeight = Matrix.HeaderRows.Count;
matrixWidth = Matrix.HeaderColumns.Count;
matrixHeight = Matrix.HeaderRows.Count - 1;
matrixWidth = Matrix.HeaderColumns.Count - 1;
}
}
@ -46,12 +48,16 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls @@ -46,12 +48,16 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
public int CellWidth { get; set; }
public HoveredCell<TValue> HoveredCell { get; set; }
public MatrixControl()
{
CellHeight = CellWidth = 36;
matrixWidth = 20;
matrixHeight = 20;
font = "Verdana";
HoveredCell = new HoveredCell<TValue>();
}
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
@ -148,20 +154,23 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls @@ -148,20 +154,23 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
cellsVertically = maxHeight > matrixHeight ? matrixHeight : maxHeight + 1;
// text
for (int i = 0; i < cellsHorizontally; i++)
for (int j = 0; j < cellsVertically; j++)
for (int i = 0; i < cellsHorizontally; i++) {
for (int j = 0; j < cellsVertically; j++) {
HoveredCell.RowIndex = i + scaledOffsetX;
HoveredCell.ColumnIndex = j + scaledOffsetY;
HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex];
drawingContext.DrawImage(
CreateText((i + scaledOffsetX) * (j + scaledOffsetY)),
CreateText(HoveredCell.Value.Text),
new Rect(i * CellWidth - offsetDiffX, j * CellHeight - offsetDiffY, CellWidth, CellHeight));
}
public ImageSource CreateText(int number)
{
return CreateText(number.ToString());
}
}
public ImageSource CreateText(string text)
{
if (text == "0") // rendering zeroes would be distracting
text = string.Empty;
if (imgs.ContainsKey(text))
return imgs[text];
@ -376,4 +385,11 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls @@ -376,4 +385,11 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
}
}
}
public class HoveredCell<TValue>
{
public int RowIndex { get; set; }
public int ColumnIndex { get; set; }
public TValue Value { get; set; }
}
}

3
src/AddIns/Analysis/CodeQuality/Src/Controls/TreeMatrixControl.xaml.cs

@ -12,6 +12,7 @@ using System.Windows.Documents; @@ -12,6 +12,7 @@ using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Forms;
using ICSharpCode.CodeQualityAnalysis.Utility;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
@ -20,7 +21,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls @@ -20,7 +21,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
/// </summary>
public partial class TreeMatrixControl : System.Windows.Controls.UserControl
{
public Matrix<INode> Matrix
public Matrix<INode, Relationship> Matrix
{
get
{

15
src/AddIns/Analysis/CodeQuality/Src/IValue.cs

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.CodeQualityAnalysis
{
/// <summary>
/// Description of IResult.
/// </summary>
public interface IValue
{
string Text { get; }
}
}

12
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml

@ -54,11 +54,18 @@ @@ -54,11 +54,18 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TabControl Grid.Row="0">
<ToolBarTray Background="White" Grid.Row="0">
<ToolBar>
<Button Name="btnOpenAssembly" Click="btnOpenAssembly_Click" Margin="0 0 5 0">Open Assembly</Button>
</ToolBar>
</ToolBarTray>
<TabControl Grid.Row="1" Name="mainTabs" IsEnabled="False"> <!-- It is enabled once assembly is loaded. -->
<TabItem Header="Dependency Graph">
<Grid>
<Grid.RowDefinitions>
@ -74,7 +81,6 @@ @@ -74,7 +81,6 @@
<ToolBarTray Background="White" Grid.Row="0" Grid.ColumnSpan="2">
<ToolBar>
<Button Name="btnOpenAssembly" Click="btnOpenAssembly_Click" Margin="0 0 5 0">Open Assembly</Button>
<Button Name="btnRelayout" Click="btnRelayout_Click" Margin="0 0 5 0">Relayout</Button>
<Button Name="btnContinueLayout" Click="btnContinueLayout_Click" Margin="0 0 5 0">Continue Layout</Button>
<Button Name="btnResetGraph" Click="btnResetGraph_Click" Margin="0 0 5 0">Reset Graph</Button>
@ -147,7 +153,7 @@ @@ -147,7 +153,7 @@
</Grid>
</TabItem>
</TabControl>
<StatusBar Grid.Row="1">
<StatusBar Grid.Row="2">
<StatusBarItem HorizontalAlignment="Left" x:Name="progressBar" Visibility="Hidden">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Loading " />

10
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs

@ -14,6 +14,7 @@ using System.Windows.Media.Imaging; @@ -14,6 +14,7 @@ using System.Windows.Media.Imaging;
using GraphSharp.Controls;
using ICSharpCode.CodeQualityAnalysis.Controls;
using ICSharpCode.CodeQualityAnalysis.Utility;
using Microsoft.Win32;
namespace ICSharpCode.CodeQualityAnalysis
@ -72,6 +73,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -72,6 +73,7 @@ namespace ICSharpCode.CodeQualityAnalysis
worker.RunWorkerCompleted += (source, args) => {
progressBar.Visibility = Visibility.Hidden;
assemblyStats.Visibility = Visibility.Visible;
mainTabs.IsEnabled = true;
FillMatrix();
};
@ -93,13 +95,13 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -93,13 +95,13 @@ namespace ICSharpCode.CodeQualityAnalysis
var matrix = new DependencyMatrix();
foreach (var ns in metricsReader.MainModule.Namespaces) {
matrix.HeaderRows.Add(new MatrixCell<INode>(ns));
matrix.HeaderRows.Add(new Cell<INode>(ns));
foreach (var type in ns.Types) {
matrix.HeaderRows.Add(new MatrixCell<INode>(type));
matrix.HeaderRows.Add(new Cell<INode>(type));
}
matrix.HeaderColumns.Add(new MatrixCell<INode>(ns));
matrix.HeaderColumns.Add(new Cell<INode>(ns));
foreach (var type in ns.Types) {
matrix.HeaderColumns.Add(new MatrixCell<INode>(type));
matrix.HeaderColumns.Add(new Cell<INode>(type));
}
}

51
src/AddIns/Analysis/CodeQuality/Src/Namespace.cs

@ -80,8 +80,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -80,8 +80,7 @@ namespace ICSharpCode.CodeQualityAnalysis
foreach (var type in ns.Types)
{
if (Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
}
@ -91,26 +90,23 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -91,26 +90,23 @@ namespace ICSharpCode.CodeQualityAnalysis
Type type = (Type)node;
if (this.Types.Contains(type.BaseType)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var thisType in type.GenericImplementedInterfacesTypes) {
if (this.Types.Contains(thisType)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
foreach (var thisType in type.ImplementedInterfaces) {
if (this.Types.Contains(thisType)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
if (this.Types.Contains(type)) {
relationship.Relationships.Add(RelationshipType.Contains);
relationship.AddRelationship(RelationshipType.Contains);
}
}
@ -118,51 +114,44 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -118,51 +114,44 @@ namespace ICSharpCode.CodeQualityAnalysis
Method method = (Method)node;
if (this.Types.Contains(method.ReturnType)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var type in method.GenericReturnTypes) {
if (this.Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
foreach (var parameter in method.Parameters) {
if (this.Types.Contains(parameter.ParameterType)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var type in parameter.GenericTypes) {
if (this.Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
}
foreach (var type in method.TypeUses) {
if (this.Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
foreach (var type in method.TypeUses) {
if (this.Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
foreach (var field in method.FieldUses) {
foreach (var type in this.Types) {
if (type.Fields.Contains(field)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
}
@ -170,40 +159,36 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -170,40 +159,36 @@ namespace ICSharpCode.CodeQualityAnalysis
foreach (var meth in method.MethodUses) {
foreach (var type in this.Types) {
if (type.Methods.Contains(meth)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
}
foreach (var type in method.TypeUses) {
if (this.Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
if (this.Types.Contains(method.DeclaringType))
relationship.Relationships.Add(RelationshipType.Contains);
relationship.AddRelationship(RelationshipType.Contains);
}
if (node is Field) {
Field field = (Field)node;
if (this.Types.Contains(field.FieldType)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var type in field.GenericTypes) {
if (this.Types.Contains(type)) {
relationship.NumberOfOccurrences++;
relationship.Relationships.Add(RelationshipType.UseThis);
relationship.AddRelationship(RelationshipType.UseThis);
}
}
if (this.Types.Contains(field.DeclaringType))
relationship.Relationships.Add(RelationshipType.Contains);
relationship.AddRelationship(RelationshipType.Contains);
}
return relationship;

18
src/AddIns/Analysis/CodeQuality/Src/Relationship.cs

@ -10,15 +10,25 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -10,15 +10,25 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary>
/// Description of Relationship.
/// </summary>
public class Relationship
public class Relationship : IValue
{
public ISet<RelationshipType> Relationships { get; private set; }
public int NumberOfOccurrences { get; set; }
public int OccurrenceCount { get; private set; }
public string Text { get { return OccurrenceCount.ToString(); } }
public Relationship()
{
Relationships = new HashSet<RelationshipType>();
NumberOfOccurrences = 0;
}
public void AddRelationship(RelationshipType type)
{
if (type == RelationshipType.UseThis)
OccurrenceCount++;
Relationships.Add(type);
}
public override string ToString()
@ -28,7 +38,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -28,7 +38,7 @@ namespace ICSharpCode.CodeQualityAnalysis
foreach (var relationship in Relationships)
builder.Append(relationship + " ");
builder.Append(NumberOfOccurrences);
builder.Append(OccurrenceCount);
return builder.ToString();
}
}

138
src/AddIns/Analysis/CodeQuality/Src/Utility/DoubleKeyDictionary.cs

@ -0,0 +1,138 @@ @@ -0,0 +1,138 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
public class DoubleKeyDictionary<K, T, V> :
IEnumerable<DoubleKeyPairValue<K, T, V>>,
IEquatable<DoubleKeyDictionary<K, T, V>>
{
private Dictionary<T, V> innerDictionary;
public DoubleKeyDictionary()
{
OuterDictionary = new Dictionary<K, Dictionary<T, V>>();
}
private Dictionary<K, Dictionary<T, V>> OuterDictionary { get; set; }
public void Add(K key1, T key2, V value)
{
if (OuterDictionary.ContainsKey(key1)) {
if (innerDictionary.ContainsKey(key2)) {
OuterDictionary[key1][key2] = value;
}
else {
innerDictionary = OuterDictionary[key1];
innerDictionary.Add(key2, value);
OuterDictionary[key1] = innerDictionary;
}
}
else {
innerDictionary = new Dictionary<T, V>();
innerDictionary[key2] = value;
OuterDictionary.Add(key1, innerDictionary);
}
}
public V this[K index1, T index2]
{
get
{
Dictionary<T, V> value1;
OuterDictionary.TryGetValue(index1, out value1);
if (value1 == null)
return default(V);
V value2;
value1.TryGetValue(index2, out value2);
if (value2 == null)
return default(V);
return value2;
}
set
{
Add(index1, index2, value);
}
}
#region IEnumerable<DoubleKeyPairValue<K,T,V>> Members
public IEnumerator<DoubleKeyPairValue<K, T, V>> GetEnumerator()
{
foreach (KeyValuePair<K, Dictionary<T, V>> outer in OuterDictionary)
foreach (KeyValuePair<T, V> inner in outer.Value)
yield return new DoubleKeyPairValue<K, T, V>(outer.Key, inner.Key, inner.Value);
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#region IEquatable<DoubleKeyDictionary<K,T,V>> Members
public bool Equals(DoubleKeyDictionary<K, T, V> other)
{
if (OuterDictionary.Keys.Count != other.OuterDictionary.Keys.Count)
return false;
bool isEqual = true;
foreach (KeyValuePair<K, Dictionary<T, V>> innerItems in OuterDictionary) {
if (!other.OuterDictionary.ContainsKey(innerItems.Key))
isEqual = false;
if (!isEqual)
break;
// here we can be sure that the key is in both lists,
// but we need to check the contents of the inner dictionary
Dictionary<T, V> otherInnerDictionary = other.OuterDictionary[innerItems.Key];
foreach (KeyValuePair<T, V> innerValue in innerItems.Value) {
if (!otherInnerDictionary.ContainsValue(innerValue.Value))
isEqual = false;
if (!otherInnerDictionary.ContainsKey(innerValue.Key))
isEqual = false;
}
if (!isEqual)
break;
}
return isEqual;
}
#endregion
}
public class DoubleKeyPairValue<K, T, V>
{
public K Key1 { get; set; }
public T Key2 { get; set; }
public V Value { get; set; }
public DoubleKeyPairValue(K key1, T key2, V value) {
Key1 = key1;
Key2 = key2;
Value = value;
}
public override string ToString()
{
return Key1.ToString() + " - " + Key2.ToString() + " - " + Value.ToString();
}
}
}

61
src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
public abstract class Matrix<TItem, TValue>
{
public List<Cell<TItem>> HeaderRows { get; set; }
public List<Cell<TItem>> HeaderColumns { get; set; }
private DoubleKeyDictionary<int, int, TValue> cache;
protected Matrix()
{
HeaderRows = new List<Cell<TItem>>();
HeaderColumns = new List<Cell<TItem>>();
cache = new DoubleKeyDictionary<int, int, TValue>();
}
private TValue GetFromCache(int rowIndex, int columnIndex)
{
return cache[rowIndex, columnIndex];
}
private void SaveToCache(int rowIndex, int columnIndex, TValue result)
{
cache.Add(rowIndex, columnIndex, result);
}
public TValue this[int rowIndex, int columnIndex]
{
get
{
var cacheResult = GetFromCache(rowIndex, columnIndex);
if (cacheResult != null)
return cacheResult;
var result = GetCellValue(rowIndex, columnIndex);
SaveToCache(rowIndex, columnIndex, result);
return result;
}
}
protected abstract TValue GetCellValue(int rowIndex, int columnIndex);
}
public class Cell<TItem>
{
public TItem Value { get; set; }
public Cell(TItem value)
{
Value = value;
}
}
}
Loading…
Cancel
Save