Browse Source

Ran .net core code formatter.

pull/131/head
Steven Kirk 11 years ago
parent
commit
145411020b
  1. BIN
      Perspex.v2.ncrunchsolution
  2. 13
      Tests/Perspex.Controls.UnitTests/GridLengthTests.cs
  3. 19
      Tests/Perspex.Markup.Xaml.UnitTests/BinderTest.cs
  4. 32
      Tests/Perspex.Markup.Xaml.UnitTests/BindingDefinitionBuilder.cs
  5. 19
      Tests/Perspex.Markup.Xaml.UnitTests/ChangeBranchTest.cs
  6. 73
      Tests/Perspex.Markup.Xaml.UnitTests/DataContextChangeSynchronizerTest.cs
  7. 5
      Tests/Perspex.Markup.Xaml.UnitTests/Properties/AssemblyInfo.cs
  8. 13
      Tests/Perspex.Markup.Xaml.UnitTests/PropertyMountPointTest.cs
  9. 21
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level1.cs
  10. 9
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level2.cs
  11. 9
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level3.cs
  12. 15
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/LogInViewModel.cs
  13. 29
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/MainWindowViewModel.cs
  14. 9
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/PropertyChangeNotifier.cs
  15. 11
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Repository.cs
  16. 23
      Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/UserRepositoriesViewModel.cs
  17. 3
      Tests/Perspex.Markup.Xaml.UnitTests/SamplePerspexObject.cs
  18. 35
      Tests/Perspex.Markup.Xaml.UnitTests/TypeProviderMock.cs
  19. 19
      Tests/Perspex.Markup.Xaml.UnitTests/ViewModelMock.cs
  20. 15
      Tests/Perspex.Markup.Xaml.UnitTests/XamlBindingTest.cs
  21. 13
      Tests/Perspex.SceneGraph.UnitTests/Media/BrushTests.cs
  22. 13
      Tests/Perspex.SceneGraph.UnitTests/Media/ColorTests.cs
  23. 9
      Tests/Perspex.SceneGraph.UnitTests/ThicknessTests.cs
  24. 13
      samples/TestApplication/App.cs
  25. 31
      samples/TestApplication/Program.cs
  26. 7
      samples/TestApplication/Properties/AssemblyInfo.cs
  27. 13
      samples/XamlTestApplication/App.cs
  28. 25
      samples/XamlTestApplication/MainViewModel.cs
  29. 37
      samples/XamlTestApplication/Program.cs
  30. 7
      samples/XamlTestApplication/Properties/AssemblyInfo.cs
  31. 25
      samples/XamlTestApplication/Views/MainWindow.cs
  32. 7
      src/Gtk/Perspex.Cairo/CairoExtensions.cs
  33. 29
      src/Gtk/Perspex.Cairo/CairoPlatform.cs
  34. 92
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  35. 35
      src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs
  36. 10
      src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs
  37. 10
      src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs
  38. 44
      src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs
  39. 40
      src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs
  40. 9
      src/Gtk/Perspex.Cairo/Properties/AssemblyInfo.cs
  41. 36
      src/Gtk/Perspex.Cairo/Renderer.cs
  42. 19
      src/Gtk/Perspex.Gtk/AssetLoader.cs
  43. 20
      src/Gtk/Perspex.Gtk/ClipboardImpl.cs
  44. 36
      src/Gtk/Perspex.Gtk/CursorFactory.cs
  45. 7
      src/Gtk/Perspex.Gtk/GtkExtensions.cs
  46. 28
      src/Gtk/Perspex.Gtk/GtkPlatform.cs
  47. 33
      src/Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs
  48. 19
      src/Gtk/Perspex.Gtk/Input/GtkMouseDevice.cs
  49. 18
      src/Gtk/Perspex.Gtk/PopupImpl.cs
  50. 7
      src/Gtk/Perspex.Gtk/Properties/AssemblyInfo.cs
  51. 61
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  52. 27
      src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs
  53. 27
      src/Markup/Perspex.Markup.Xaml/Context/PerspexParserFactory.cs
  54. 27
      src/Markup/Perspex.Markup.Xaml/Context/PerspexTypeRepository.cs
  55. 47
      src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs
  56. 19
      src/Markup/Perspex.Markup.Xaml/Context/PerspexXamlMember.cs
  57. 37
      src/Markup/Perspex.Markup.Xaml/Context/PerspexXamlMemberValuePlugin.cs
  58. 23
      src/Markup/Perspex.Markup.Xaml/Context/PerspexXamlType.cs
  59. 15
      src/Markup/Perspex.Markup.Xaml/Converters/BitmapConverter.cs
  60. 15
      src/Markup/Perspex.Markup.Xaml/Converters/BrushConverter.cs
  61. 15
      src/Markup/Perspex.Markup.Xaml/Converters/ColumnDefinitionsTypeConverter.cs
  62. 15
      src/Markup/Perspex.Markup.Xaml/Converters/GridLengthTypeConverter.cs
  63. 15
      src/Markup/Perspex.Markup.Xaml/Converters/RowDefinitionsTypeConverter.cs
  64. 13
      src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs
  65. 47
      src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/ObservablePropertyBranch.cs
  66. 23
      src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/PropertyMountPoint.cs
  67. 19
      src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/PropertyPath.cs
  68. 29
      src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/TargettedProperty.cs
  69. 87
      src/Markup/Perspex.Markup.Xaml/DataBinding/DataContextChangeSynchronizer.cs
  70. 9
      src/Markup/Perspex.Markup.Xaml/DataBinding/IPerspexPropertyBinder.cs
  71. 31
      src/Markup/Perspex.Markup.Xaml/DataBinding/PerspexPropertyBinder.cs
  72. 11
      src/Markup/Perspex.Markup.Xaml/DataBinding/SourceBindingEndpoint.cs
  73. 7
      src/Markup/Perspex.Markup.Xaml/DataBinding/TargetBindingEndpoint.cs
  74. 31
      src/Markup/Perspex.Markup.Xaml/DataBinding/XamlBinding.cs
  75. 35
      src/Markup/Perspex.Markup.Xaml/DataBinding/XamlBindingDefinition.cs
  76. 17
      src/Markup/Perspex.Markup.Xaml/MarkupExtensions/BindingExtension.cs
  77. 17
      src/Markup/Perspex.Markup.Xaml/MarkupExtensions/TypeExtension.cs
  78. 19
      src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs
  79. 7
      src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs
  80. 7
      src/Markup/Perspex.Markup.Xaml/Templates/Template.cs
  81. 27
      src/Markup/Perspex.Markup.Xaml/Templates/TemplateContent.cs
  82. 11
      src/Markup/Perspex.Markup.Xaml/Templates/TemplateLoader.cs
  83. 15
      src/Markup/Perspex.Markup.Xaml/Templates/XamlDataTemplate.cs
  84. 5
      src/NGenerics/Constants.cs
  85. 74
      src/NGenerics/DataStructures/Comparers/ComparisonComparer.cs
  86. 41
      src/NGenerics/DataStructures/Comparers/KeyValuePairComparer.cs
  87. 29
      src/NGenerics/DataStructures/Comparers/ReverseComparer.cs
  88. 139
      src/NGenerics/DataStructures/General/Heap.cs
  89. 3
      src/NGenerics/DataStructures/General/HeapType.cs
  90. 53
      src/NGenerics/DataStructures/General/IHeap.cs
  91. 41
      src/NGenerics/DataStructures/Queues/IQueue.cs
  92. 107
      src/NGenerics/DataStructures/Queues/PriorityQueue.cs
  93. 3
      src/NGenerics/DataStructures/Queues/PriorityQueueType.cs
  94. 62
      src/NGenerics/DataStructures/Trees/BinarySearchTreeBase.cs
  95. 252
      src/NGenerics/DataStructures/Trees/BinaryTree.cs
  96. 9
      src/NGenerics/DataStructures/Trees/ISearchTree.cs
  97. 13
      src/NGenerics/DataStructures/Trees/ITree.cs
  98. 3
      src/NGenerics/DataStructures/Trees/NodeColor.cs
  99. 120
      src/NGenerics/DataStructures/Trees/RedBlackTree.cs
  100. 436
      src/NGenerics/DataStructures/Trees/RedBlackTreeDictionary.cs

BIN
Perspex.v2.ncrunchsolution

Binary file not shown.

13
Tests/Perspex.Controls.UnitTests/GridLengthTests.cs

@ -1,15 +1,12 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Linq;
using Xunit;
namespace Perspex.Controls.UnitTests namespace Perspex.Controls.UnitTests
{ {
using System;
using System.Linq;
using Xunit;
public class GridLengthTests public class GridLengthTests
{ {
[Fact] [Fact]

19
Tests/Perspex.Markup.Xaml.UnitTests/BinderTest.cs

@ -1,14 +1,17 @@
namespace Perspex.Xaml.Base.UnitTest // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Moq; using System;
using Markup.Xaml.DataBinding; using Moq;
using OmniXaml.TypeConversion; using Perspex.Markup.Xaml.DataBinding;
using Xunit; using OmniXaml.TypeConversion;
using Xunit;
namespace Perspex.Xaml.Base.UnitTest
{
public class BinderTest public class BinderTest
{ {
[Fact] [Fact]
public void NullTarget_Throws() public void NullTarget_Throws()
{ {
var typeConverter = new Mock<ITypeConverterProvider>(); var typeConverter = new Mock<ITypeConverterProvider>();

32
Tests/Perspex.Markup.Xaml.UnitTests/BindingDefinitionBuilder.cs

@ -1,37 +1,39 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using Perspex.Controls;
using Perspex.Markup.Xaml.DataBinding;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Xaml.Base.UnitTest namespace Perspex.Xaml.Base.UnitTest
{ {
using Controls;
using Markup.Xaml.DataBinding;
using Markup.Xaml.DataBinding.ChangeTracking;
public class BindingDefinitionBuilder public class BindingDefinitionBuilder
{ {
private readonly BindingMode bindingMode; private readonly BindingMode _bindingMode;
private readonly PropertyPath sourcePropertyPath; private readonly PropertyPath _sourcePropertyPath;
private Control target; private Control _target;
private PerspexProperty targetProperty; private PerspexProperty _targetProperty;
public BindingDefinitionBuilder() public BindingDefinitionBuilder()
{ {
bindingMode = BindingMode.Default; _bindingMode = BindingMode.Default;
sourcePropertyPath = new PropertyPath(string.Empty); _sourcePropertyPath = new PropertyPath(string.Empty);
} }
public BindingDefinitionBuilder WithNullTarget() public BindingDefinitionBuilder WithNullTarget()
{ {
target = null; _target = null;
return this; return this;
} }
public XamlBindingDefinition Build() public XamlBindingDefinition Build()
{ {
return new XamlBindingDefinition( return new XamlBindingDefinition(
bindingMode: bindingMode, bindingMode: _bindingMode,
sourcePropertyPath: sourcePropertyPath, sourcePropertyPath: _sourcePropertyPath,
target: target, target: _target,
targetProperty: targetProperty); targetProperty: _targetProperty);
} }
} }
} }

19
Tests/Perspex.Markup.Xaml.UnitTests/ChangeBranchTest.cs

@ -1,10 +1,13 @@
namespace Perspex.Xaml.Base.UnitTest // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Markup.Xaml.DataBinding.ChangeTracking; using System;
using SampleModel; using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
using Xunit; using Perspex.Xaml.Base.UnitTest.SampleModel;
using Xunit;
namespace Perspex.Xaml.Base.UnitTest
{
public class ChangeBranchTest public class ChangeBranchTest
{ {
[Fact] [Fact]
@ -23,11 +26,11 @@
public void OnePathOnly() public void OnePathOnly()
{ {
var level1 = new Level1(); var level1 = new Level1();
var branch = new ObservablePropertyBranch(level1, new PropertyPath("Text")); var branch = new ObservablePropertyBranch(level1, new PropertyPath("Text"));
var newValue = "Hey now"; var newValue = "Hey now";
branch.Value = newValue; branch.Value = newValue;
Assert.Equal(level1.Text, newValue); Assert.Equal(level1.Text, newValue);
} }

73
Tests/Perspex.Markup.Xaml.UnitTests/DataContextChangeSynchronizerTest.cs

@ -1,84 +1,87 @@
namespace Perspex.Xaml.Base.UnitTest // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Controls;
using GitHubClient.ViewModels;
using Perspex.Markup.Xaml.DataBinding;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
using OmniXaml.Builder;
using OmniXaml.TypeConversion;
using OmniXaml.TypeConversion.BuiltInConverters;
using Perspex.Xaml.Base.UnitTest.SampleModel;
using Xunit;
namespace Perspex.Xaml.Base.UnitTest
{ {
using System;
using Controls;
using GitHubClient.ViewModels;
using Markup.Xaml.DataBinding;
using Markup.Xaml.DataBinding.ChangeTracking;
using OmniXaml.Builder;
using OmniXaml.TypeConversion;
using OmniXaml.TypeConversion.BuiltInConverters;
using SampleModel;
using Xunit;
public class DataContextChangeSynchronizerTest public class DataContextChangeSynchronizerTest
{ {
private TypeConverterProvider repo; private TypeConverterProvider _repo;
private SamplePerspexObject guiObject; private SamplePerspexObject _guiObject;
private ViewModelMock viewModel; private ViewModelMock _viewModel;
public DataContextChangeSynchronizerTest() public DataContextChangeSynchronizerTest()
{ {
repo = new TypeConverterProvider(); _repo = new TypeConverterProvider();
guiObject = new SamplePerspexObject(); _guiObject = new SamplePerspexObject();
viewModel = new ViewModelMock(); _viewModel = new ViewModelMock();
} }
[Fact] [Fact]
public void SameTypesFromUIToModel() public void SameTypesFromUIToModel()
{ {
var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), viewModel), new DataContextChangeSynchronizer.BindingTarget(guiObject, SamplePerspexObject.IntProperty), repo); var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), _viewModel), new DataContextChangeSynchronizer.BindingTarget(_guiObject, SamplePerspexObject.IntProperty), _repo);
synchronizer.StartUpdatingSourceWhenTargetChanges(); synchronizer.StartUpdatingSourceWhenTargetChanges();
const int someValue = 4; const int someValue = 4;
guiObject.Int = someValue; _guiObject.Int = someValue;
Assert.Equal(someValue, viewModel.IntProp); Assert.Equal(someValue, _viewModel.IntProp);
} }
[Fact] [Fact]
public void DifferentTypesFromUIToModel() public void DifferentTypesFromUIToModel()
{ {
var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), viewModel), new DataContextChangeSynchronizer.BindingTarget(guiObject, SamplePerspexObject.StringProperty), repo); var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), _viewModel), new DataContextChangeSynchronizer.BindingTarget(_guiObject, SamplePerspexObject.StringProperty), _repo);
synchronizer.StartUpdatingSourceWhenTargetChanges(); synchronizer.StartUpdatingSourceWhenTargetChanges();
guiObject.String = "2"; _guiObject.String = "2";
Assert.Equal(2, viewModel.IntProp); Assert.Equal(2, _viewModel.IntProp);
} }
[Fact] [Fact]
public void DifferentTypesAndNonConvertibleValueFromUIToModel() public void DifferentTypesAndNonConvertibleValueFromUIToModel()
{ {
var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), viewModel), new DataContextChangeSynchronizer.BindingTarget(guiObject, SamplePerspexObject.StringProperty), repo); var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), _viewModel), new DataContextChangeSynchronizer.BindingTarget(_guiObject, SamplePerspexObject.StringProperty), _repo);
synchronizer.StartUpdatingSourceWhenTargetChanges(); synchronizer.StartUpdatingSourceWhenTargetChanges();
guiObject.String = ""; _guiObject.String = "";
Assert.Equal(default(int), viewModel.IntProp); Assert.Equal(default(int), _viewModel.IntProp);
} }
[Fact] [Fact]
public void DifferentTypesFromModelToUI() public void DifferentTypesFromModelToUI()
{ {
var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), viewModel), new DataContextChangeSynchronizer.BindingTarget(guiObject, SamplePerspexObject.StringProperty), repo); var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), _viewModel), new DataContextChangeSynchronizer.BindingTarget(_guiObject, SamplePerspexObject.StringProperty), _repo);
synchronizer.StartUpdatingTargetWhenSourceChanges(); synchronizer.StartUpdatingTargetWhenSourceChanges();
viewModel.IntProp = 2; _viewModel.IntProp = 2;
Assert.Equal("2", guiObject.String); Assert.Equal("2", _guiObject.String);
} }
[Fact] [Fact]
public void SameTypesFromModelToUI() public void SameTypesFromModelToUI()
{ {
var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), viewModel), new DataContextChangeSynchronizer.BindingTarget(guiObject, SamplePerspexObject.IntProperty), repo); var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("IntProp"), _viewModel), new DataContextChangeSynchronizer.BindingTarget(_guiObject, SamplePerspexObject.IntProperty), _repo);
synchronizer.StartUpdatingTargetWhenSourceChanges(); synchronizer.StartUpdatingTargetWhenSourceChanges();
viewModel.IntProp = 2; _viewModel.IntProp = 2;
Assert.Equal(2, guiObject.Int); Assert.Equal(2, _guiObject.Int);
} }
[Fact] [Fact]
@ -87,7 +90,7 @@
var mainWindowViewModel = new MainWindowViewModel(); var mainWindowViewModel = new MainWindowViewModel();
var contentControl = new ContentControl(); var contentControl = new ContentControl();
var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("Content"), mainWindowViewModel), new DataContextChangeSynchronizer.BindingTarget(contentControl, ContentControl.ContentProperty), repo); var synchronizer = new DataContextChangeSynchronizer(new DataContextChangeSynchronizer.BindingSource(new PropertyPath("Content"), mainWindowViewModel), new DataContextChangeSynchronizer.BindingTarget(contentControl, ContentControl.ContentProperty), _repo);
synchronizer.StartUpdatingTargetWhenSourceChanges(); synchronizer.StartUpdatingTargetWhenSourceChanges();

5
Tests/Perspex.Markup.Xaml.UnitTests/Properties/AssemblyInfo.cs

@ -1,3 +1,6 @@
using System.Reflection; // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection;
[assembly: AssemblyTitle("Perspex.Markup.Xaml.UnitTests")] [assembly: AssemblyTitle("Perspex.Markup.Xaml.UnitTests")]

13
Tests/Perspex.Markup.Xaml.UnitTests/PropertyMountPointTest.cs

@ -1,9 +1,12 @@
namespace Perspex.Xaml.Base.UnitTest // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Markup.Xaml.DataBinding.ChangeTracking;
using System; using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
using Xunit; using System;
using Xunit;
namespace Perspex.Xaml.Base.UnitTest
{
public class PropertyMountPointTest public class PropertyMountPointTest
{ {
[Fact] [Fact]

21
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level1.cs

@ -1,39 +1,42 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
namespace Perspex.Xaml.Base.UnitTest.SampleModel namespace Perspex.Xaml.Base.UnitTest.SampleModel
{ {
public class Level1 : PropertyChangeNotifier public class Level1 : PropertyChangeNotifier
{ {
private Level2 level2 = new Level2(); private Level2 _level2 = new Level2();
private DateTime dateTime; private DateTime _dateTime;
private string text; private string _text;
public Level2 Level2 public Level2 Level2
{ {
get { return level2; } get { return _level2; }
set set
{ {
level2 = value; _level2 = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }
public string Text public string Text
{ {
get { return text; } get { return _text; }
set set
{ {
text = value; _text = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }
public DateTime DateTime public DateTime DateTime
{ {
get { return dateTime; } get { return _dateTime; }
set set
{ {
dateTime = value; _dateTime = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }

9
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level2.cs

@ -1,15 +1,18 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Xaml.Base.UnitTest.SampleModel namespace Perspex.Xaml.Base.UnitTest.SampleModel
{ {
public class Level2 : PropertyChangeNotifier public class Level2 : PropertyChangeNotifier
{ {
private Level3 level3 = new Level3(); private Level3 _level3 = new Level3();
public Level3 Level3 public Level3 Level3
{ {
get { return level3; } get { return _level3; }
set set
{ {
level3 = value; _level3 = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }

9
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level3.cs

@ -1,15 +1,18 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Xaml.Base.UnitTest.SampleModel namespace Perspex.Xaml.Base.UnitTest.SampleModel
{ {
public class Level3 : PropertyChangeNotifier public class Level3 : PropertyChangeNotifier
{ {
private int property = 10; private int _property = 10;
public int Property public int Property
{ {
get { return property; } get { return _property; }
set set
{ {
property = value; _property = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }

15
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/LogInViewModel.cs

@ -1,16 +1,13 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using ReactiveUI;
namespace Perspex.Xaml.Base.UnitTest.SampleModel namespace Perspex.Xaml.Base.UnitTest.SampleModel
{ {
using ReactiveUI;
public class LogInViewModel : ReactiveObject public class LogInViewModel : ReactiveObject
{ {
private string username; private string _username;
public LogInViewModel() public LogInViewModel()
{ {
@ -22,8 +19,8 @@ namespace Perspex.Xaml.Base.UnitTest.SampleModel
public string Username public string Username
{ {
get { return this.username; } get { return _username; }
set { this.RaiseAndSetIfChanged(ref this.username, value); } set { this.RaiseAndSetIfChanged(ref _username, value); }
} }
public ReactiveCommand<object> OkCommand public ReactiveCommand<object> OkCommand

29
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/MainWindowViewModel.cs

@ -1,20 +1,17 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Xaml.Base.UnitTest.SampleModel;
using ReactiveUI;
namespace GitHubClient.ViewModels namespace GitHubClient.ViewModels
{ {
using System;
using Perspex.Xaml.Base.UnitTest.SampleModel;
using ReactiveUI;
public class MainWindowViewModel : ReactiveObject public class MainWindowViewModel : ReactiveObject
{ {
private object content; private object _content;
private LogInViewModel login; private LogInViewModel _login;
public MainWindowViewModel() public MainWindowViewModel()
{ {
@ -23,21 +20,21 @@ namespace GitHubClient.ViewModels
public object Content public object Content
{ {
get { return this.content; } get { return _content; }
set { this.RaiseAndSetIfChanged(ref this.content, value); } set { this.RaiseAndSetIfChanged(ref _content, value); }
} }
private void ShowLogin() private void ShowLogin()
{ {
this.login = new LogInViewModel(); _login = new LogInViewModel();
this.login.OkCommand.Subscribe(_ => this.ShowRepositories()); _login.OkCommand.Subscribe(_ => this.ShowRepositories());
this.Content = this.login; this.Content = _login;
} }
private void ShowRepositories() private void ShowRepositories()
{ {
var vm = new UserRepositoriesViewModel(); var vm = new UserRepositoriesViewModel();
var task = vm.Load(this.login.Username); var task = vm.Load(_login.Username);
this.Content = vm; this.Content = vm;
} }
} }

9
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/PropertyChangeNotifier.cs

@ -1,8 +1,11 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Perspex.Xaml.Base.UnitTest.SampleModel namespace Perspex.Xaml.Base.UnitTest.SampleModel
{ {
using System.ComponentModel;
using System.Runtime.CompilerServices;
public abstract class PropertyChangeNotifier : INotifyPropertyChanged public abstract class PropertyChangeNotifier : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;

11
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Repository.cs

@ -1,17 +1,20 @@
namespace GitHubClient.ViewModels // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace GitHubClient.ViewModels
{ {
public class Repository public class Repository
{ {
private readonly string name; private readonly string _name;
public Repository(string name) public Repository(string name)
{ {
this.name = name; _name = name;
} }
public string Name public string Name
{ {
get { return name; } get { return _name; }
} }
} }
} }

23
Tests/Perspex.Markup.Xaml.UnitTests/SampleModel/UserRepositoriesViewModel.cs

@ -1,29 +1,26 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using System.Threading.Tasks;
using GitHubClient.ViewModels;
using ReactiveUI;
namespace Perspex.Xaml.Base.UnitTest.SampleModel namespace Perspex.Xaml.Base.UnitTest.SampleModel
{ {
using System.Collections.Generic;
using System.Threading.Tasks;
using GitHubClient.ViewModels;
using ReactiveUI;
public class UserRepositoriesViewModel : ReactiveObject public class UserRepositoriesViewModel : ReactiveObject
{ {
private IReadOnlyList<Repository> repositories; private IReadOnlyList<Repository> _repositories;
public async Task Load(string username) public async Task Load(string username)
{ {
this.Repositories = await new Task<IReadOnlyList<Repository>>(() => new List<Repository> { new Repository("Blah"), new Repository("Bleh") }); this.Repositories = await new Task<IReadOnlyList<Repository>>(() => new List<Repository> { new Repository("Blah"), new Repository("Bleh") });
} }
public IReadOnlyList<Repository> Repositories public IReadOnlyList<Repository> Repositories
{ {
get { return this.repositories; } get { return _repositories; }
private set { this.RaiseAndSetIfChanged(ref this.repositories, value); } private set { this.RaiseAndSetIfChanged(ref _repositories, value); }
} }
} }
} }

3
Tests/Perspex.Markup.Xaml.UnitTests/SamplePerspexObject.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
namespace Perspex.Xaml.Base.UnitTest namespace Perspex.Xaml.Base.UnitTest

35
Tests/Perspex.Markup.Xaml.UnitTests/TypeProviderMock.cs

@ -1,21 +1,24 @@
namespace Perspex.Xaml.Base.UnitTest // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using OmniXaml;
using System; using OmniXaml;
using System;
class TypeProviderMock : ITypeProvider namespace Perspex.Xaml.Base.UnitTest
{
internal class TypeProviderMock : ITypeProvider
{ {
private readonly string typeName; private readonly string _typeName;
private readonly string clrNamespace; private readonly string _clrNamespace;
private readonly string assemblyName; private readonly string _assemblyName;
private readonly Type typeToReturn; private readonly Type _typeToReturn;
public TypeProviderMock(string typeName, string clrNamespace, string assemblyName, Type typeToReturn) public TypeProviderMock(string typeName, string clrNamespace, string assemblyName, Type typeToReturn)
{ {
this.typeName = typeName; _typeName = typeName;
this.clrNamespace = clrNamespace; _clrNamespace = clrNamespace;
this.assemblyName = assemblyName; _assemblyName = assemblyName;
this.typeToReturn = typeToReturn; _typeToReturn = typeToReturn;
} }
public TypeProviderMock() public TypeProviderMock()
@ -24,10 +27,10 @@
public Type GetType(string typeName, string clrNamespace, string assemblyName) public Type GetType(string typeName, string clrNamespace, string assemblyName)
{ {
if (this.typeName == typeName && this.clrNamespace == clrNamespace && this.assemblyName == assemblyName) if (_typeName == typeName && _clrNamespace == clrNamespace && _assemblyName == assemblyName)
{ {
return typeToReturn; return _typeToReturn;
} }
throw new TypeNotFoundException("The Type cannot be found"); throw new TypeNotFoundException("The Type cannot be found");
} }

19
Tests/Perspex.Markup.Xaml.UnitTests/ViewModelMock.cs

@ -1,29 +1,32 @@
using System.ComponentModel; // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace Perspex.Xaml.Base.UnitTest namespace Perspex.Xaml.Base.UnitTest
{ {
class ViewModelMock : INotifyPropertyChanged internal class ViewModelMock : INotifyPropertyChanged
{ {
private string str; private string _str;
private int intProp; private int _intProp;
public int IntProp public int IntProp
{ {
get { return intProp; } get { return _intProp; }
set set
{ {
intProp = value; _intProp = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }
public string StrProp public string StrProp
{ {
get { return str; } get { return _str; }
set set
{ {
str = value; _str = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }

15
Tests/Perspex.Markup.Xaml.UnitTests/XamlBindingTest.cs

@ -1,10 +1,13 @@
namespace Perspex.Xaml.Base.UnitTest // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Moq;
using Markup.Xaml.DataBinding; using Moq;
using OmniXaml.TypeConversion; using Perspex.Markup.Xaml.DataBinding;
using Xunit; using OmniXaml.TypeConversion;
using Xunit;
namespace Perspex.Xaml.Base.UnitTest
{
public class XamlBindingTest public class XamlBindingTest
{ {
[Fact] [Fact]

13
Tests/Perspex.SceneGraph.UnitTests/Media/BrushTests.cs

@ -1,15 +1,12 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Media;
using Xunit;
namespace Perspex.SceneGraph.UnitTests.Media namespace Perspex.SceneGraph.UnitTests.Media
{ {
using System;
using Perspex.Media;
using Xunit;
public class BrushTests public class BrushTests
{ {
[Fact] [Fact]

13
Tests/Perspex.SceneGraph.UnitTests/Media/ColorTests.cs

@ -1,15 +1,12 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Media;
using Xunit;
namespace Perspex.SceneGraph.UnitTests.Media namespace Perspex.SceneGraph.UnitTests.Media
{ {
using System;
using Perspex.Media;
using Xunit;
public class ColorTests public class ColorTests
{ {
[Fact] [Fact]

9
Tests/Perspex.SceneGraph.UnitTests/ThicknessTests.cs

@ -1,13 +1,10 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Xunit;
namespace Perspex.SceneGraph.UnitTests.Media namespace Perspex.SceneGraph.UnitTests.Media
{ {
using Xunit;
public class ThicknessTests public class ThicknessTests
{ {
[Fact] [Fact]

13
samples/TestApplication/App.cs

@ -1,9 +1,12 @@
namespace TestApplication // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex; using System;
using Perspex.Themes.Default; using Perspex;
using Perspex.Themes.Default;
namespace TestApplication
{
public class App : Application public class App : Application
{ {
public App() public App()

31
samples/TestApplication/Program.cs

@ -1,4 +1,7 @@
using System; // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive.Linq; using System.Reactive.Linq;
using Perspex; using Perspex;
using Perspex.Animation; using Perspex.Animation;
@ -18,13 +21,13 @@ using ReactiveUI;
namespace TestApplication namespace TestApplication
{ {
class Item internal class Item
{ {
public string Name { get; set; } public string Name { get; set; }
public string Value { get; set; } public string Value { get; set; }
} }
class Node internal class Node
{ {
public Node() public Node()
{ {
@ -35,9 +38,9 @@ namespace TestApplication
public PerspexList<Node> Children { get; set; } public PerspexList<Node> Children { get; set; }
} }
class Program internal class Program
{ {
private static PerspexList<Node> treeData = new PerspexList<Node> private static PerspexList<Node> s_treeData = new PerspexList<Node>
{ {
new Node new Node
{ {
@ -75,7 +78,7 @@ namespace TestApplication
}, },
}; };
private static PerspexList<Item> listBoxData = new PerspexList<Item> private static PerspexList<Item> s_listBoxData = new PerspexList<Item>
{ {
new Item { Name = "Item 1", Value = "Item 1 Value" }, new Item { Name = "Item 1", Value = "Item 1 Value" },
new Item { Name = "Item 2", Value = "Item 2 Value" }, new Item { Name = "Item 2", Value = "Item 2 Value" },
@ -87,7 +90,7 @@ namespace TestApplication
new Item { Name = "Item 8", Value = "Item 8 Value" }, new Item { Name = "Item 8", Value = "Item 8 Value" },
}; };
static void Main(string[] args) private static void Main(string[] args)
{ {
//Log.Logger = new LoggerConfiguration() //Log.Logger = new LoggerConfiguration()
// .Filter.ByIncludingOnly(Matching.WithProperty("Area", "Layout")) // .Filter.ByIncludingOnly(Matching.WithProperty("Area", "Layout"))
@ -264,7 +267,7 @@ namespace TestApplication
var showDialog = ReactiveCommand.Create(); var showDialog = ReactiveCommand.Create();
Button showDialogButton; Button showDialogButton;
var result = new TabItem var result = new TabItem
{ {
Header = "Buttons", Header = "Buttons",
@ -356,7 +359,7 @@ namespace TestApplication
close.Subscribe(x => dialog.Close(x)); close.Subscribe(x => dialog.Close(x));
showDialogButton.Content = await dialog.ShowDialog<string>(); showDialogButton.Content = await dialog.ShowDialog<string>();
}); });
return result; return result;
@ -402,7 +405,7 @@ namespace TestApplication
new TextBox new TextBox
{ {
AcceptsReturn = true, AcceptsReturn = true,
Text = "A wrapping text box. " + Text = "A wrapping text box. " +
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt. " +
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.",
TextWrapping = TextWrapping.Wrap, TextWrapping = TextWrapping.Wrap,
@ -488,17 +491,17 @@ namespace TestApplication
new TreeView new TreeView
{ {
Name = "treeView", Name = "treeView",
Items = treeData, Items = s_treeData,
}, },
(listBox = new ListBox (listBox = new ListBox
{ {
Items = listBoxData, Items = s_listBoxData,
MaxHeight = 300, MaxHeight = 300,
}), }),
new DropDown new DropDown
{ {
Items = listBoxData, Items = s_listBoxData,
SelectedItem = listBoxData[0], SelectedItem = s_listBoxData[0],
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
} }
} }

7
samples/TestApplication/Properties/AssemblyInfo.cs

@ -1,4 +1,7 @@
using System.Reflection; // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -10,7 +13,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestApplication")] [assembly: AssemblyProduct("TestApplication")]
[assembly: AssemblyCopyright("Copyright © 2013")] [assembly: AssemblyCopyright("Copyright \u00A9 2013")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

13
samples/XamlTestApplication/App.cs

@ -1,9 +1,12 @@
namespace XamlTestApplication // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex; using System;
using Perspex.Themes.Default; using Perspex;
using Perspex.Themes.Default;
namespace XamlTestApplication
{
public class App : Application public class App : Application
{ {
public App() public App()

25
samples/XamlTestApplication/MainViewModel.cs

@ -1,15 +1,18 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using ReactiveUI;
namespace XamlTestApplication namespace XamlTestApplication
{ {
using System.Collections.Generic;
using ReactiveUI;
public class MainViewModel : ReactiveObject public class MainViewModel : ReactiveObject
{ {
private string name; private string _name;
public MainViewModel() public MainViewModel()
{ {
Name = "José Manuel"; Name = "Jos\u00E9 Manuel";
People = new List<Person> People = new List<Person>
{ {
new Person("a little bit of Monica in my life"), new Person("a little bit of Monica in my life"),
@ -24,8 +27,8 @@ namespace XamlTestApplication
public string Name public string Name
{ {
get { return name; } get { return _name; }
set { this.RaiseAndSetIfChanged(ref name, value); } set { this.RaiseAndSetIfChanged(ref _name, value); }
} }
public List<Person> People { get; set; } public List<Person> People { get; set; }
@ -33,17 +36,17 @@ namespace XamlTestApplication
public class Person public class Person
{ {
private string name; private string _name;
public Person(string name) public Person(string name)
{ {
this.name = name; _name = name;
} }
public string Name public string Name
{ {
get { return name; } get { return _name; }
set { name = value; } set { _name = value; }
} }
} }
} }

37
samples/XamlTestApplication/Program.cs

@ -1,22 +1,25 @@
namespace XamlTestApplication // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Diagnostics;
using System.Windows.Threading;
using Perspex;
using Perspex.Collections;
using Perspex.Controls;
using Perspex.Controls.Templates;
using ReactiveUI;
using XamlTestApplication.Views;
namespace XamlTestApplication
{ {
using System; internal class Item
using System.Diagnostics;
using System.Windows.Threading;
using Perspex;
using Perspex.Collections;
using Perspex.Controls;
using Perspex.Controls.Templates;
using ReactiveUI;
using Views;
class Item
{ {
public string Name { get; set; } public string Name { get; set; }
public string Value { get; set; } public string Value { get; set; }
} }
class Node internal class Node
{ {
public Node() public Node()
{ {
@ -27,9 +30,9 @@
public PerspexList<Node> Children { get; set; } public PerspexList<Node> Children { get; set; }
} }
class Program internal class Program
{ {
static void Main() private static void Main()
{ {
var foo = Dispatcher.CurrentDispatcher; var foo = Dispatcher.CurrentDispatcher;
@ -46,10 +49,10 @@
var testCommand = ReactiveCommand.Create(); var testCommand = ReactiveCommand.Create();
testCommand.Subscribe(_ => Debug.WriteLine("Test command executed.")); testCommand.Subscribe(_ => Debug.WriteLine("Test command executed."));
var window = new MainWindow(); var window = new MainWindow();
window.Show(); window.Show();
Application.Current.Run(window); Application.Current.Run(window);
} }
} }
} }

7
samples/XamlTestApplication/Properties/AssemblyInfo.cs

@ -1,4 +1,7 @@
using System.Reflection; // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -10,7 +13,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestApplication")] [assembly: AssemblyProduct("TestApplication")]
[assembly: AssemblyCopyright("Copyright © 2013")] [assembly: AssemblyCopyright("Copyright \u00A9 2013")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

25
samples/XamlTestApplication/Views/MainWindow.cs

@ -1,15 +1,18 @@
namespace XamlTestApplication.Views // Copyright (c) The Perspex Project. All rights reserved.
{ // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization; using System;
using System.IO; using System.Globalization;
using System.Reflection; using System.IO;
using System.Resources; using System.Reflection;
using OmniXaml; using System.Resources;
using Perspex.Controls; using OmniXaml;
using Perspex.Diagnostics; using Perspex.Controls;
using Perspex.Markup.Xaml; using Perspex.Diagnostics;
using Perspex.Markup.Xaml;
namespace XamlTestApplication.Views
{
public class MainWindow : Window public class MainWindow : Window
{ {
public MainWindow() public MainWindow()

7
src/Gtk/Perspex.Cairo/CairoExtensions.cs

@ -1,8 +1,5 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Cairo namespace Perspex.Cairo
{ {

29
src/Gtk/Perspex.Cairo/CairoPlatform.cs

@ -1,28 +1,25 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Cairo.Media;
using Perspex.Cairo.Media.Imaging;
using Perspex.Media;
using Perspex.Platform;
using Splat;
namespace Perspex.Cairo namespace Perspex.Cairo
{ {
using System;
using global::Cairo; using global::Cairo;
using Perspex.Cairo.Media;
using Perspex.Cairo.Media.Imaging;
using Perspex.Media;
using Perspex.Platform;
using Perspex.Threading;
using Splat;
public class CairoPlatform : IPlatformRenderInterface public class CairoPlatform : IPlatformRenderInterface
{ {
private static CairoPlatform instance = new CairoPlatform(); private static CairoPlatform s_instance = new CairoPlatform();
public static void Initialize() public static void Initialize()
{ {
var locator = Locator.CurrentMutable; var locator = Locator.CurrentMutable;
locator.Register(() => instance, typeof(IPlatformRenderInterface)); locator.Register(() => s_instance, typeof(IPlatformRenderInterface));
} }
public IBitmapImpl CreateBitmap(int width, int height) public IBitmapImpl CreateBitmap(int width, int height)
@ -31,9 +28,9 @@ namespace Perspex.Cairo
} }
public IFormattedTextImpl CreateFormattedText( public IFormattedTextImpl CreateFormattedText(
string text, string text,
string fontFamily, string fontFamily,
double fontSize, double fontSize,
FontStyle fontStyle, FontStyle fontStyle,
TextAlignment textAlignment, TextAlignment textAlignment,
Perspex.Media.FontWeight fontWeight) Perspex.Media.FontWeight fontWeight)

92
src/Gtk/Perspex.Cairo/Media/DrawingContext.cs

@ -1,19 +1,15 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive.Disposables;
using Perspex.Cairo.Media.Imaging;
using Perspex.Media;
using IBitmap = Perspex.Media.Imaging.IBitmap;
namespace Perspex.Cairo.Media namespace Perspex.Cairo.Media
{ {
using System;
using System.Reactive.Disposables;
using Perspex.Cairo.Media.Imaging;
using Perspex.Media;
using Perspex.Platform;
using Splat;
using Cairo = global::Cairo; using Cairo = global::Cairo;
using IBitmap = Perspex.Media.Imaging.IBitmap;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Draws using Direct2D1. /// Draws using Direct2D1.
@ -23,15 +19,15 @@ namespace Perspex.Cairo.Media
/// <summary> /// <summary>
/// The cairo context. /// The cairo context.
/// </summary> /// </summary>
private Cairo.Context context; private Cairo.Context _context;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DrawingContext"/> class. /// Initializes a new instance of the <see cref="DrawingContext"/> class.
/// </summary> /// </summary>
/// <param name="surface">The target surface.</param> /// <param name="surface">The target surface.</param>
public DrawingContext(Cairo.Surface surface) public DrawingContext(Cairo.Surface surface)
{ {
this.context = new Cairo.Context(surface); _context = new Cairo.Context(surface);
this.CurrentTransform = Matrix.Identity; this.CurrentTransform = Matrix.Identity;
} }
@ -41,7 +37,7 @@ namespace Perspex.Cairo.Media
/// <param name="surface">The GDK drawable.</param> /// <param name="surface">The GDK drawable.</param>
public DrawingContext(Gdk.Drawable drawable) public DrawingContext(Gdk.Drawable drawable)
{ {
this.context = Gdk.CairoHelper.Create(drawable); _context = Gdk.CairoHelper.Create(drawable);
this.CurrentTransform = Matrix.Identity; this.CurrentTransform = Matrix.Identity;
} }
@ -56,7 +52,7 @@ namespace Perspex.Cairo.Media
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
this.context.Dispose(); _context.Dispose();
} }
public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect) public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
@ -66,12 +62,12 @@ namespace Perspex.Cairo.Media
var scaleX = destRect.Size.Width / sourceRect.Size.Width; var scaleX = destRect.Size.Width / sourceRect.Size.Width;
var scaleY = destRect.Size.Height / sourceRect.Size.Height; var scaleY = destRect.Size.Height / sourceRect.Size.Height;
this.context.Save(); _context.Save();
this.context.Scale(scaleX, scaleY); _context.Scale(scaleX, scaleY);
this.context.SetSourceSurface(impl.Surface, (int)sourceRect.X, (int)sourceRect.Y); _context.SetSourceSurface(impl.Surface, (int)sourceRect.X, (int)sourceRect.Y);
this.context.Rectangle(sourceRect.ToCairo()); _context.Rectangle(sourceRect.ToCairo());
this.context.Fill(); _context.Fill();
this.context.Restore(); _context.Restore();
} }
/// <summary> /// <summary>
@ -83,12 +79,12 @@ namespace Perspex.Cairo.Media
public void DrawLine(Pen pen, Perspex.Point p1, Perspex.Point p2) public void DrawLine(Pen pen, Perspex.Point p1, Perspex.Point p2)
{ {
var size = new Rect(p1, p2).Size; var size = new Rect(p1, p2).Size;
this.SetBrush(pen.Brush, size); this.SetBrush(pen.Brush, size);
this.context.LineWidth = pen.Thickness; _context.LineWidth = pen.Thickness;
this.context.MoveTo(p1.ToCairo()); _context.MoveTo(p1.ToCairo());
this.context.LineTo(p2.ToCairo()); _context.LineTo(p2.ToCairo());
this.context.Stroke(); _context.Stroke();
} }
/// <summary> /// <summary>
@ -100,26 +96,26 @@ namespace Perspex.Cairo.Media
public void DrawGeometry(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry) public void DrawGeometry(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry)
{ {
var impl = geometry.PlatformImpl as StreamGeometryImpl; var impl = geometry.PlatformImpl as StreamGeometryImpl;
using (var pop = this.PushTransform(impl.Transform)) using (var pop = this.PushTransform(impl.Transform))
{ {
this.context.AppendPath(impl.Path); _context.AppendPath(impl.Path);
if (brush != null) if (brush != null)
{ {
this.SetBrush(brush, geometry.Bounds.Size); this.SetBrush(brush, geometry.Bounds.Size);
if (pen != null) if (pen != null)
this.context.FillPreserve(); _context.FillPreserve();
else else
this.context.Fill(); _context.Fill();
} }
if (pen != null) if (pen != null)
{ {
this.SetPen(pen, geometry.Bounds.Size); this.SetPen(pen, geometry.Bounds.Size);
this.context.Stroke(); _context.Stroke();
} }
} }
} }
@ -132,8 +128,8 @@ namespace Perspex.Cairo.Media
public void DrawRectange(Pen pen, Rect rect, float cornerRadius) public void DrawRectange(Pen pen, Rect rect, float cornerRadius)
{ {
this.SetPen(pen, rect.Size); this.SetPen(pen, rect.Size);
this.context.Rectangle(rect.ToCairo()); _context.Rectangle(rect.ToCairo());
this.context.Stroke(); _context.Stroke();
} }
/// <summary> /// <summary>
@ -146,9 +142,9 @@ namespace Perspex.Cairo.Media
{ {
var layout = ((FormattedTextImpl)text.PlatformImpl).Layout; var layout = ((FormattedTextImpl)text.PlatformImpl).Layout;
this.SetBrush(foreground, new Size(0, 0)); this.SetBrush(foreground, new Size(0, 0));
this.context.MoveTo(origin.X, origin.Y); _context.MoveTo(origin.X, origin.Y);
Pango.CairoHelper.ShowLayout(this.context, layout); Pango.CairoHelper.ShowLayout(_context, layout);
} }
/// <summary> /// <summary>
@ -159,8 +155,8 @@ namespace Perspex.Cairo.Media
public void FillRectange(Perspex.Media.Brush brush, Rect rect, float cornerRadius) public void FillRectange(Perspex.Media.Brush brush, Rect rect, float cornerRadius)
{ {
this.SetBrush(brush, rect.Size); this.SetBrush(brush, rect.Size);
this.context.Rectangle(rect.ToCairo()); _context.Rectangle(rect.ToCairo());
this.context.Fill(); _context.Fill();
} }
/// <summary> /// <summary>
@ -170,10 +166,10 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the clip rectangle.</returns> /// <returns>A disposable used to undo the clip rectangle.</returns>
public IDisposable PushClip(Rect clip) public IDisposable PushClip(Rect clip)
{ {
this.context.Rectangle(clip.ToCairo()); _context.Rectangle(clip.ToCairo());
this.context.Clip(); _context.Clip();
return Disposable.Create(() => this.context.ResetClip()); return Disposable.Create(() => _context.ResetClip());
} }
/// <summary> /// <summary>
@ -194,11 +190,11 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the transformation.</returns> /// <returns>A disposable used to undo the transformation.</returns>
public IDisposable PushTransform(Matrix matrix) public IDisposable PushTransform(Matrix matrix)
{ {
this.context.Transform(matrix.ToCairo()); _context.Transform(matrix.ToCairo());
return Disposable.Create(() => return Disposable.Create(() =>
{ {
this.context.Transform(matrix.Invert().ToCairo()); _context.Transform(matrix.Invert().ToCairo());
}); });
} }
@ -209,7 +205,7 @@ namespace Perspex.Cairo.Media
if (solid != null) if (solid != null)
{ {
this.context.SetSourceRGBA( _context.SetSourceRGBA(
solid.Color.R / 255.0, solid.Color.R / 255.0,
solid.Color.G / 255.0, solid.Color.G / 255.0,
solid.Color.B / 255.0, solid.Color.B / 255.0,
@ -224,14 +220,14 @@ namespace Perspex.Cairo.Media
g.Extend = Cairo.Extend.Pad; g.Extend = Cairo.Extend.Pad;
this.context.SetSource(g); _context.SetSource(g);
} }
} }
private void SetPen(Pen pen, Size destinationSize) private void SetPen(Pen pen, Size destinationSize)
{ {
this.SetBrush(pen.Brush, destinationSize); this.SetBrush(pen.Brush, destinationSize);
this.context.LineWidth = pen.Thickness; _context.LineWidth = pen.Thickness;
} }
} }
} }

35
src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs

@ -1,18 +1,15 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Perspex.Media;
using Perspex.Platform;
using Splat;
namespace Perspex.Cairo.Media namespace Perspex.Cairo.Media
{ {
using System;
using System.Collections.Generic;
using System.Linq;
using Perspex.Media;
using Perspex.Platform;
using Splat;
public class FormattedTextImpl : IFormattedTextImpl public class FormattedTextImpl : IFormattedTextImpl
{ {
public FormattedTextImpl( public FormattedTextImpl(
@ -33,21 +30,21 @@ namespace Perspex.Cairo.Media
Style = (Pango.Style)fontStyle, Style = (Pango.Style)fontStyle,
Weight = fontWeight.ToCairo() Weight = fontWeight.ToCairo()
}; };
this.Layout.Alignment = textAlignment.ToCairo(); this.Layout.Alignment = textAlignment.ToCairo();
} }
private Size size; private Size _size;
public Size Constraint public Size Constraint
{ {
get get
{ {
return size; return _size;
} }
set set
{ {
this.size = value; _size = value;
this.Layout.Width = Pango.Units.FromDouble(value.Width); this.Layout.Width = Pango.Units.FromDouble(value.Width);
} }
} }
@ -95,12 +92,12 @@ namespace Perspex.Cairo.Media
public IEnumerable<Rect> HitTestTextRange(int index, int length) public IEnumerable<Rect> HitTestTextRange(int index, int length)
{ {
var ranges = new List<Rect>(); var ranges = new List<Rect>();
for (var i = 0; i < length; i++) for (var i = 0; i < length; i++)
{ {
ranges.Add(this.HitTestTextPosition(index+i)); ranges.Add(this.HitTestTextPosition(index + i));
} }
return ranges; return ranges;
} }
@ -109,7 +106,7 @@ namespace Perspex.Cairo.Media
int width; int width;
int height; int height;
this.Layout.GetPixelSize(out width, out height); this.Layout.GetPixelSize(out width, out height);
return new Size(width, height); return new Size(width, height);
} }

10
src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs

@ -1,13 +1,11 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Platform;
namespace Perspex.Cairo.Media.Imaging namespace Perspex.Cairo.Media.Imaging
{ {
using System;
using Perspex.Platform;
using Cairo = global::Cairo; using Cairo = global::Cairo;
public class BitmapImpl : IBitmapImpl public class BitmapImpl : IBitmapImpl

10
src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs

@ -1,13 +1,11 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Platform;
namespace Perspex.Cairo.Media.Imaging namespace Perspex.Cairo.Media.Imaging
{ {
using System;
using Perspex.Platform;
using Cairo = global::Cairo; using Cairo = global::Cairo;
public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl

44
src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs

@ -1,25 +1,23 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using Perspex.Media;
using Perspex.Platform;
namespace Perspex.Cairo.Media namespace Perspex.Cairo.Media
{ {
using Perspex.Media;
using Perspex.Platform;
using System;
using System.Collections.Generic;
using Cairo = global::Cairo; using Cairo = global::Cairo;
public class StreamGeometryContextImpl : IStreamGeometryContextImpl public class StreamGeometryContextImpl : IStreamGeometryContextImpl
{ {
private StreamGeometryImpl impl; private StreamGeometryImpl _impl;
public StreamGeometryContextImpl(StreamGeometryImpl imp) public StreamGeometryContextImpl(StreamGeometryImpl imp)
{ {
this.impl = imp; _impl = imp;
this.surf = new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0); _surf = new Cairo.ImageSurface(global::Cairo.Format.Argb32, 0, 0);
this.context = new Cairo.Context(this.surf); _context = new Cairo.Context(_surf);
} }
public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection) public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection)
@ -28,36 +26,36 @@ namespace Perspex.Cairo.Media
public void BeginFigure(Point startPoint, bool isFilled) public void BeginFigure(Point startPoint, bool isFilled)
{ {
this.context.MoveTo(startPoint.ToCairo()); _context.MoveTo(startPoint.ToCairo());
} }
public void BezierTo(Point point1, Point point2, Point point3) public void BezierTo(Point point1, Point point2, Point point3)
{ {
this.context.CurveTo(point1.ToCairo(), point2.ToCairo(), point3.ToCairo()); _context.CurveTo(point1.ToCairo(), point2.ToCairo(), point3.ToCairo());
} }
public void LineTo(Point point) public void LineTo(Point point)
{ {
this.context.LineTo(point.ToCairo()); _context.LineTo(point.ToCairo());
} }
private Cairo.Context context; private Cairo.Context _context;
private Cairo.ImageSurface surf; private Cairo.ImageSurface _surf;
public void EndFigure(bool isClosed) public void EndFigure(bool isClosed)
{ {
if (isClosed) if (isClosed)
this.context.ClosePath(); _context.ClosePath();
var extents = this.context.StrokeExtents(); var extents = _context.StrokeExtents();
this.impl.Bounds = new Rect(extents.X, extents.Y, extents.Width, extents.Height); _impl.Bounds = new Rect(extents.X, extents.Y, extents.Width, extents.Height);
this.impl.Path = this.context.CopyPath(); _impl.Path = _context.CopyPath();
} }
public void Dispose() public void Dispose()
{ {
context.Dispose(); _context.Dispose();
surf.Dispose(); _surf.Dispose();
} }
} }
} }

40
src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs

@ -1,32 +1,30 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Media;
using Perspex.Platform;
using Splat;
using System.Collections.Generic;
namespace Perspex.Cairo.Media namespace Perspex.Cairo.Media
{ {
using System;
using Perspex.Media;
using Perspex.Platform;
using Cairo = global::Cairo; using Cairo = global::Cairo;
using Splat;
using System.Collections.Generic;
public class StreamGeometryImpl : IStreamGeometryImpl public class StreamGeometryImpl : IStreamGeometryImpl
{ {
public StreamGeometryImpl() public StreamGeometryImpl()
{ {
this.impl = new StreamGeometryContextImpl(this); _impl = new StreamGeometryContextImpl(this);
} }
public StreamGeometryImpl(Cairo.Path path) public StreamGeometryImpl(Cairo.Path path)
{ {
this.impl = new StreamGeometryContextImpl(this); _impl = new StreamGeometryContextImpl(this);
this.Path = path; this.Path = path;
} }
public Cairo.Path Path public global::Cairo.Path Path
{ {
get; get;
set; set;
@ -38,20 +36,20 @@ namespace Perspex.Cairo.Media
set; set;
} }
private StreamGeometryContextImpl impl; private StreamGeometryContextImpl _impl;
private Matrix transform = Matrix.Identity; private Matrix _transform = Matrix.Identity;
public Matrix Transform public Matrix Transform
{ {
get { return this.transform; } get { return _transform; }
set set
{ {
if (value != this.Transform) if (value != this.Transform)
{ {
if (!value.IsIdentity) if (!value.IsIdentity)
{ {
this.transform = value; _transform = value;
} }
} }
} }
} }
@ -68,7 +66,7 @@ namespace Perspex.Cairo.Media
public IStreamGeometryContextImpl Open() public IStreamGeometryContextImpl Open()
{ {
return this.impl; return _impl;
} }
} }
} }

9
src/Gtk/Perspex.Cairo/Properties/AssemblyInfo.cs

@ -1,8 +1,5 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -16,7 +13,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Perspex.Cairo")] [assembly: AssemblyProduct("Perspex.Cairo")]
[assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyCopyright("Copyright \u00A9 2014")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

36
src/Gtk/Perspex.Cairo/Renderer.cs

@ -1,27 +1,24 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
using Perspex.Cairo.Media;
using Perspex.Media;
using Perspex.Platform;
using Perspex.Rendering;
namespace Perspex.Cairo namespace Perspex.Cairo
{ {
using System;
using System.Runtime.InteropServices;
using global::Cairo; using global::Cairo;
using Perspex.Cairo.Media;
using Perspex.Media;
using Perspex.Platform;
using Perspex.Rendering;
using Matrix = Perspex.Matrix;
/// <summary> /// <summary>
/// A cairo renderer. /// A cairo renderer.
/// </summary> /// </summary>
public class Renderer : RendererBase public class Renderer : RendererBase
{ {
private Surface surface; private Surface _surface;
private Gdk.Window window; private Gdk.Window _window;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Renderer"/> class. /// Initializes a new instance of the <see cref="Renderer"/> class.
@ -35,7 +32,7 @@ namespace Perspex.Cairo
public Renderer(ImageSurface surface) public Renderer(ImageSurface surface)
{ {
this.surface = surface; _surface = surface;
} }
/// <summary> /// <summary>
@ -47,7 +44,7 @@ namespace Perspex.Cairo
{ {
// Don't need to do anything here. // Don't need to do anything here.
} }
/// <summary> /// <summary>
/// Creates a cairo surface that targets a platform-specific resource. /// Creates a cairo surface that targets a platform-specific resource.
@ -56,16 +53,15 @@ namespace Perspex.Cairo
/// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns> /// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns>
protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle) protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle)
{ {
switch (handle.HandleDescriptor) switch (handle.HandleDescriptor)
{ {
case "RTB": case "RTB":
return new DrawingContext(this.surface); return new DrawingContext(_surface);
case "GdkWindow": case "GdkWindow":
if (this.window == null) if (_window == null)
this.window = new Gdk.Window(handle.Handle); _window = new Gdk.Window(handle.Handle);
return new DrawingContext(this.window); return new DrawingContext(_window);
default: default:
throw new NotSupportedException(string.Format( throw new NotSupportedException(string.Format(
"Don't know how to create a Cairo renderer from a '{0}' handle", "Don't know how to create a Cairo renderer from a '{0}' handle",

19
src/Gtk/Perspex.Gtk/AssetLoader.cs

@ -1,18 +1,15 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using Perspex.Platform;
namespace Perspex.Gtk namespace Perspex.Gtk
{ {
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using Perspex.Platform;
/// <summary> /// <summary>
/// Loads assets compiled into the application binary. /// Loads assets compiled into the application binary.
/// </summary> /// </summary>

20
src/Gtk/Perspex.Gtk/ClipboardImpl.cs

@ -1,14 +1,16 @@
namespace Perspex.Gtk // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Threading.Tasks;
using Gdk;
using Perspex.Input.Platform;
namespace Perspex.Gtk
{ {
using Gdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Perspex.Input.Platform;
using Gtk = global::Gtk; using Gtk = global::Gtk;
class ClipboardImpl : IClipboard
internal class ClipboardImpl : IClipboard
{ {
private static Gtk.Clipboard GetClipboard() => Gtk.Clipboard.GetForDisplay(Gdk.Display.Default, new Atom(IntPtr.Zero)); private static Gtk.Clipboard GetClipboard() => Gtk.Clipboard.GetForDisplay(Gdk.Display.Default, new Atom(IntPtr.Zero));

36
src/Gtk/Perspex.Gtk/CursorFactory.cs

@ -1,15 +1,16 @@
namespace Perspex.Gtk // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using Gdk;
using Perspex.Input;
using Perspex.Platform;
namespace Perspex.Gtk
{ {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gdk;
using Gtk = global::Gtk; using Gtk = global::Gtk;
using Perspex.Input;
using Perspex.Platform; internal class CursorFactory : IStandardCursorFactory
class CursorFactory : IStandardCursorFactory
{ {
public static CursorFactory Instance { get; } = new CursorFactory(); public static CursorFactory Instance { get; } = new CursorFactory();
@ -17,7 +18,7 @@
{ {
} }
private static readonly Dictionary<StandardCursorType, object> CursorTypeMapping = new Dictionary private static readonly Dictionary<StandardCursorType, object> s_cursorTypeMapping = new Dictionary
<StandardCursorType, object> <StandardCursorType, object>
{ {
{ StandardCursorType.AppStarting, CursorType.Watch }, { StandardCursorType.AppStarting, CursorType.Watch },
@ -36,10 +37,10 @@
{ StandardCursorType.Help, Gtk.Stock.Help } { StandardCursorType.Help, Gtk.Stock.Help }
}; };
private static readonly Dictionary<StandardCursorType, IPlatformHandle> Cache = private static readonly Dictionary<StandardCursorType, IPlatformHandle> s_cache =
new Dictionary<StandardCursorType, IPlatformHandle>(); new Dictionary<StandardCursorType, IPlatformHandle>();
Gdk.Cursor GetCursor(object desc) private Gdk.Cursor GetCursor(object desc)
{ {
Gdk.Cursor rv; Gdk.Cursor rv;
var name = desc as string; var name = desc as string;
@ -51,23 +52,22 @@
} }
else else
{ {
rv = new Gdk.Cursor((CursorType) desc); rv = new Gdk.Cursor((CursorType)desc);
} }
rv.Owned = false; rv.Owned = false;
return rv; return rv;
} }
public IPlatformHandle GetCursor(StandardCursorType cursorType) public IPlatformHandle GetCursor(StandardCursorType cursorType)
{ {
IPlatformHandle rv; IPlatformHandle rv;
if (!Cache.TryGetValue(cursorType, out rv)) if (!s_cache.TryGetValue(cursorType, out rv))
{ {
Cache[cursorType] = s_cache[cursorType] =
rv = rv =
new PlatformHandle( new PlatformHandle(
GetCursor(CursorTypeMapping[cursorType]).Handle, GetCursor(s_cursorTypeMapping[cursorType]).Handle,
"GTKCURSOR"); "GTKCURSOR");
} }

7
src/Gtk/Perspex.Gtk/GtkExtensions.cs

@ -1,8 +1,5 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Gtk namespace Perspex.Gtk
{ {

28
src/Gtk/Perspex.Gtk/GtkPlatform.cs

@ -1,22 +1,20 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive.Disposables;
using Perspex.Input.Platform;
using Perspex.Input;
using Perspex.Platform;
using Splat;
namespace Perspex.Gtk namespace Perspex.Gtk
{ {
using System;
using System.Reactive.Disposables;
using Perspex.Input.Platform;
using Perspex.Input;
using Perspex.Platform;
using Splat;
using Gtk = global::Gtk; using Gtk = global::Gtk;
public class GtkPlatform : IPlatformThreadingInterface, IPlatformSettings public class GtkPlatform : IPlatformThreadingInterface, IPlatformSettings
{ {
private static GtkPlatform instance = new GtkPlatform(); private static GtkPlatform s_instance = new GtkPlatform();
public GtkPlatform() public GtkPlatform()
{ {
@ -42,11 +40,11 @@ namespace Perspex.Gtk
var locator = Locator.CurrentMutable; var locator = Locator.CurrentMutable;
locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); locator.Register(() => new WindowImpl(), typeof(IWindowImpl));
locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new PopupImpl(), typeof(IPopupImpl));
locator.Register(() => new ClipboardImpl(), typeof (IClipboard)); locator.Register(() => new ClipboardImpl(), typeof(IClipboard));
locator.Register(() => CursorFactory.Instance, typeof(IStandardCursorFactory)); locator.Register(() => CursorFactory.Instance, typeof(IStandardCursorFactory));
locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice));
locator.Register(() => instance, typeof(IPlatformSettings)); locator.Register(() => s_instance, typeof(IPlatformSettings));
locator.Register(() => instance, typeof(IPlatformThreadingInterface)); locator.Register(() => s_instance, typeof(IPlatformThreadingInterface));
locator.RegisterConstant(new AssetLoader(), typeof(IAssetLoader)); locator.RegisterConstant(new AssetLoader(), typeof(IAssetLoader));
} }
@ -64,7 +62,7 @@ namespace Perspex.Gtk
{ {
var result = true; var result = true;
var handle = GLib.Timeout.Add( var handle = GLib.Timeout.Add(
(uint)interval.TotalMilliseconds, (uint)interval.TotalMilliseconds,
() => () =>
{ {
tick(); tick();

33
src/Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs

@ -1,30 +1,27 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Reflection;
using Perspex.Input;
namespace Perspex.Gtk namespace Perspex.Gtk
{ {
using System;
using System.Collections.Generic;
using System.Reflection;
using Perspex.Input;
public class GtkKeyboardDevice : KeyboardDevice public class GtkKeyboardDevice : KeyboardDevice
{ {
private static GtkKeyboardDevice instance; private static GtkKeyboardDevice s_instance;
private static readonly Dictionary<Gdk.Key, string> NameDic = new Dictionary<Gdk.Key, string>(); private static readonly Dictionary<Gdk.Key, string> s_nameDic = new Dictionary<Gdk.Key, string>();
static GtkKeyboardDevice() static GtkKeyboardDevice()
{ {
instance = new GtkKeyboardDevice(); s_instance = new GtkKeyboardDevice();
foreach (var f in typeof (Gdk.Key).GetFields(BindingFlags.Public | BindingFlags.Static)) foreach (var f in typeof(Gdk.Key).GetFields(BindingFlags.Public | BindingFlags.Static))
{ {
var key = (Gdk.Key) f.GetValue(null); var key = (Gdk.Key)f.GetValue(null);
if(NameDic.ContainsKey(key)) if (s_nameDic.ContainsKey(key))
continue; continue;
NameDic[key] = f.Name; s_nameDic[key] = f.Name;
} }
} }
@ -34,7 +31,7 @@ namespace Perspex.Gtk
public static new GtkKeyboardDevice Instance public static new GtkKeyboardDevice Instance
{ {
get { return instance; } get { return s_instance; }
} }
public static Perspex.Input.Key ConvertKey(Gdk.Key key) public static Perspex.Input.Key ConvertKey(Gdk.Key key)
@ -47,7 +44,7 @@ namespace Perspex.Gtk
else else
{ {
string s; string s;
if (!NameDic.TryGetValue(key, out s)) if (!s_nameDic.TryGetValue(key, out s))
s = "Unknown"; s = "Unknown";
Perspex.Input.Key result; Perspex.Input.Key result;

19
src/Gtk/Perspex.Gtk/Input/GtkMouseDevice.cs

@ -1,21 +1,18 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Input;
namespace Perspex.Gtk namespace Perspex.Gtk
{ {
using Perspex.Input;
public class GtkMouseDevice : MouseDevice public class GtkMouseDevice : MouseDevice
{ {
private static GtkMouseDevice instance; private static GtkMouseDevice s_instance;
private Point clientPosition; private Point _clientPosition;
static GtkMouseDevice() static GtkMouseDevice()
{ {
instance = new GtkMouseDevice(); s_instance = new GtkMouseDevice();
} }
private GtkMouseDevice() private GtkMouseDevice()
@ -24,12 +21,12 @@ namespace Perspex.Gtk
public static new GtkMouseDevice Instance public static new GtkMouseDevice Instance
{ {
get { return instance; } get { return s_instance; }
} }
internal void SetClientPosition(Point p) internal void SetClientPosition(Point p)
{ {
this.clientPosition = p; _clientPosition = p;
} }
} }
} }

18
src/Gtk/Perspex.Gtk/PopupImpl.cs

@ -1,22 +1,18 @@
using System; // Copyright (c) The Perspex Project. All rights reserved.
using System.Collections.Generic; // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Linq;
using System.Text; using Gtk;
using System.Threading.Tasks; using Perspex.Platform;
namespace Perspex.Gtk namespace Perspex.Gtk
{ {
using System;
using Perspex.Platform;
using global::Gtk;
public class PopupImpl : WindowImpl, IPopupImpl public class PopupImpl : WindowImpl, IPopupImpl
{ {
public PopupImpl() public PopupImpl()
: base(WindowType.Popup) : base(WindowType.Popup)
{ {
} }
public void SetPosition(Point p) public void SetPosition(Point p)
{ {
this.Move((int)p.X, (int)p.Y); this.Move((int)p.X, (int)p.Y);

7
src/Gtk/Perspex.Gtk/Properties/AssemblyInfo.cs

@ -1,8 +1,5 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;

61
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -1,35 +1,32 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive.Disposables;
using Gdk; using Gdk;
using Perspex.Controls;
using Perspex.Input.Raw;
using Perspex.Platform;
using Perspex.Input; using Perspex.Input;
using Action = System.Action;
namespace Perspex.Gtk namespace Perspex.Gtk
{ {
using System;
using System.Threading.Tasks;
using Perspex.Controls;
using Perspex.Input.Raw;
using Perspex.Platform;
using Gtk = global::Gtk; using Gtk = global::Gtk;
using System.Reactive.Disposables;
public class WindowImpl : Gtk.Window, IWindowImpl public class WindowImpl : Gtk.Window, IWindowImpl
{ {
private TopLevel owner; private TopLevel _owner;
private IPlatformHandle windowHandle; private IPlatformHandle _windowHandle;
private Size clientSize; private Size _clientSize;
private Gtk.IMContext imContext; private Gtk.IMContext _imContext;
private uint lastKeyEventTimestamp; private uint _lastKeyEventTimestamp;
private static readonly Gdk.Cursor DefaultCursor = new Gdk.Cursor(CursorType.LeftPtr); private static readonly Gdk.Cursor s_defaultCursor = new Gdk.Cursor(CursorType.LeftPtr);
public WindowImpl() public WindowImpl()
: base(Gtk.WindowType.Toplevel) : base(Gtk.WindowType.Toplevel)
@ -49,9 +46,9 @@ namespace Perspex.Gtk
this.Events = Gdk.EventMask.PointerMotionMask | this.Events = Gdk.EventMask.PointerMotionMask |
Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonPressMask |
Gdk.EventMask.ButtonReleaseMask; Gdk.EventMask.ButtonReleaseMask;
this.windowHandle = new PlatformHandle(this.Handle, "GtkWindow"); _windowHandle = new PlatformHandle(this.Handle, "GtkWindow");
this.imContext = new Gtk.IMMulticontext(); _imContext = new Gtk.IMMulticontext();
this.imContext.Commit += ImContext_Commit; _imContext.Commit += ImContext_Commit;
} }
public Size ClientSize public Size ClientSize
@ -62,7 +59,7 @@ namespace Perspex.Gtk
IPlatformHandle ITopLevelImpl.Handle IPlatformHandle ITopLevelImpl.Handle
{ {
get { return this.windowHandle; } get { return _windowHandle; }
} }
public Action Activated { get; set; } public Action Activated { get; set; }
@ -93,13 +90,13 @@ namespace Perspex.Gtk
{ {
int x, y; int x, y;
this.GdkWindow.GetDeskrelativeOrigin(out x, out y); this.GdkWindow.GetDeskrelativeOrigin(out x, out y);
return new Point(point.X + x, point.Y + y); return new Point(point.X + x, point.Y + y);
} }
public void SetOwner(TopLevel owner) public void SetOwner(TopLevel owner)
{ {
this.owner = owner; _owner = owner;
} }
public void SetTitle(string title) public void SetTitle(string title)
@ -110,7 +107,7 @@ namespace Perspex.Gtk
public void SetCursor(IPlatformHandle cursor) public void SetCursor(IPlatformHandle cursor)
{ {
GdkWindow.Cursor = cursor != null ? new Gdk.Cursor(cursor.Handle) : DefaultCursor; GdkWindow.Cursor = cursor != null ? new Gdk.Cursor(cursor.Handle) : s_defaultCursor;
} }
public IDisposable ShowDialog() public IDisposable ShowDialog()
@ -144,7 +141,7 @@ namespace Perspex.Gtk
var e = new RawMouseEventArgs( var e = new RawMouseEventArgs(
GtkMouseDevice.Instance, GtkMouseDevice.Instance,
evnt.Time, evnt.Time,
this.owner, _owner,
RawMouseEventType.LeftButtonDown, RawMouseEventType.LeftButtonDown,
new Point(evnt.X, evnt.Y), GetModifierKeys(evnt.State)); new Point(evnt.X, evnt.Y), GetModifierKeys(evnt.State));
this.Input(e); this.Input(e);
@ -156,7 +153,7 @@ namespace Perspex.Gtk
var e = new RawMouseEventArgs( var e = new RawMouseEventArgs(
GtkMouseDevice.Instance, GtkMouseDevice.Instance,
evnt.Time, evnt.Time,
this.owner, _owner,
RawMouseEventType.LeftButtonUp, RawMouseEventType.LeftButtonUp,
new Point(evnt.X, evnt.Y), GetModifierKeys(evnt.State)); new Point(evnt.X, evnt.Y), GetModifierKeys(evnt.State));
this.Input(e); this.Input(e);
@ -166,8 +163,8 @@ namespace Perspex.Gtk
protected override bool OnConfigureEvent(Gdk.EventConfigure evnt) protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
{ {
var newSize = new Size(evnt.Width, evnt.Height); var newSize = new Size(evnt.Width, evnt.Height);
if (newSize != this.clientSize) if (newSize != _clientSize)
{ {
this.Resized(newSize); this.Resized(newSize);
} }
@ -182,8 +179,8 @@ namespace Perspex.Gtk
private bool ProcessKeyEvent(Gdk.EventKey evnt) private bool ProcessKeyEvent(Gdk.EventKey evnt)
{ {
this.lastKeyEventTimestamp = evnt.Time; _lastKeyEventTimestamp = evnt.Time;
if (this.imContext.FilterKeypress(evnt)) if (_imContext.FilterKeypress(evnt))
return true; return true;
var e = new RawKeyEventArgs( var e = new RawKeyEventArgs(
GtkKeyboardDevice.Instance, GtkKeyboardDevice.Instance,
@ -200,7 +197,7 @@ namespace Perspex.Gtk
private void ImContext_Commit(object o, Gtk.CommitArgs args) private void ImContext_Commit(object o, Gtk.CommitArgs args)
{ {
this.Input(new RawTextInputEventArgs(GtkKeyboardDevice.Instance, this.lastKeyEventTimestamp, args.Str)); this.Input(new RawTextInputEventArgs(GtkKeyboardDevice.Instance, _lastKeyEventTimestamp, args.Str));
} }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) protected override bool OnExposeEvent(Gdk.EventExpose evnt)
@ -223,7 +220,7 @@ namespace Perspex.Gtk
var e = new RawMouseEventArgs( var e = new RawMouseEventArgs(
GtkMouseDevice.Instance, GtkMouseDevice.Instance,
evnt.Time, evnt.Time,
this.owner, _owner,
RawMouseEventType.Move, RawMouseEventType.Move,
position, GetModifierKeys(evnt.State)); position, GetModifierKeys(evnt.State));
this.Input(e); this.Input(e);

27
src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs

@ -1,19 +1,16 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using OmniXaml;
using OmniXaml.ObjectAssembler;
using Perspex.Markup.Xaml.Templates;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using System;
using OmniXaml;
using OmniXaml.ObjectAssembler;
using Templates;
public class PerspexObjectAssembler : IObjectAssembler public class PerspexObjectAssembler : IObjectAssembler
{ {
private readonly TemplateHostingObjectAssembler objectAssembler; private readonly TemplateHostingObjectAssembler _objectAssembler;
public PerspexObjectAssembler(IWiringContext wiringContext, ObjectAssemblerSettings objectAssemblerSettings = null) public PerspexObjectAssembler(IWiringContext wiringContext, ObjectAssemblerSettings objectAssemblerSettings = null)
{ {
@ -21,24 +18,24 @@ namespace Perspex.Markup.Xaml.Context
mapping.Map<XamlDataTemplate>(template => template.Content, new TemplateLoader()); mapping.Map<XamlDataTemplate>(template => template.Content, new TemplateLoader());
var assembler = new ObjectAssembler(wiringContext, new TopDownMemberValueContext(), objectAssemblerSettings); var assembler = new ObjectAssembler(wiringContext, new TopDownMemberValueContext(), objectAssemblerSettings);
this.objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping); _objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);
} }
public object Result => this.objectAssembler.Result; public object Result => _objectAssembler.Result;
public EventHandler<XamlSetValueEventArgs> XamlSetValueHandler { get; set; } public EventHandler<XamlSetValueEventArgs> XamlSetValueHandler { get; set; }
public IWiringContext WiringContext => this.objectAssembler.WiringContext; public IWiringContext WiringContext => _objectAssembler.WiringContext;
public void Process(XamlInstruction node) public void Process(XamlInstruction node)
{ {
this.objectAssembler.Process(node); _objectAssembler.Process(node);
} }
public void OverrideInstance(object instance) public void OverrideInstance(object instance)
{ {
this.objectAssembler.OverrideInstance(instance); _objectAssembler.OverrideInstance(instance);
} }
} }
} }

27
src/Markup/Perspex.Markup.Xaml/Context/PerspexParserFactory.cs

@ -1,19 +1,16 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using OmniXaml;
using OmniXaml.ObjectAssembler;
using OmniXaml.Parsers.ProtoParser;
using OmniXaml.Parsers.XamlInstructions;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using OmniXaml;
using OmniXaml.ObjectAssembler;
using OmniXaml.Parsers.ProtoParser;
using OmniXaml.Parsers.XamlInstructions;
public class PerspexParserFactory : IXamlParserFactory public class PerspexParserFactory : IXamlParserFactory
{ {
private readonly IWiringContext wiringContext; private readonly IWiringContext _wiringContext;
public PerspexParserFactory() public PerspexParserFactory()
: this(new TypeFactory()) : this(new TypeFactory())
@ -22,7 +19,7 @@ namespace Perspex.Markup.Xaml.Context
public PerspexParserFactory(ITypeFactory typeFactory) public PerspexParserFactory(ITypeFactory typeFactory)
{ {
this.wiringContext = new PerspexWiringContext(typeFactory); _wiringContext = new PerspexWiringContext(typeFactory);
} }
public IXamlParser CreateForReadingFree() public IXamlParser CreateForReadingFree()
@ -34,10 +31,10 @@ namespace Perspex.Markup.Xaml.Context
private IXamlParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot) private IXamlParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot)
{ {
var xamlInstructionParser = new OrderAwareXamlInstructionParser(new XamlInstructionParser(this.wiringContext)); var xamlInstructionParser = new OrderAwareXamlInstructionParser(new XamlInstructionParser(_wiringContext));
var phaseParserKit = new PhaseParserKit( var phaseParserKit = new PhaseParserKit(
new XamlProtoInstructionParser(this.wiringContext), new XamlProtoInstructionParser(_wiringContext),
xamlInstructionParser, xamlInstructionParser,
objectAssemblerForUndefinedRoot); objectAssemblerForUndefinedRoot);
@ -46,7 +43,7 @@ namespace Perspex.Markup.Xaml.Context
private IObjectAssembler GetObjectAssemblerForUndefinedRoot() private IObjectAssembler GetObjectAssemblerForUndefinedRoot()
{ {
return new ObjectAssembler(this.wiringContext, new TopDownMemberValueContext()); return new ObjectAssembler(_wiringContext, new TopDownMemberValueContext());
} }
public IXamlParser CreateForReadingSpecificInstance(object rootInstance) public IXamlParser CreateForReadingSpecificInstance(object rootInstance)
@ -58,7 +55,7 @@ namespace Perspex.Markup.Xaml.Context
private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance) private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance)
{ {
return new PerspexObjectAssembler(this.wiringContext, new ObjectAssemblerSettings { RootInstance = rootInstance }); return new PerspexObjectAssembler(_wiringContext, new ObjectAssemblerSettings { RootInstance = rootInstance });
} }
} }
} }

27
src/Markup/Perspex.Markup.Xaml/Context/PerspexTypeRepository.cs

@ -1,35 +1,32 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Glass;
using OmniXaml;
using OmniXaml.Typing;
using Perspex.Markup.Xaml.DataBinding;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using System;
using DataBinding;
using Glass;
using OmniXaml;
using OmniXaml.Typing;
public class PerspexTypeRepository : XamlTypeRepository public class PerspexTypeRepository : XamlTypeRepository
{ {
private readonly ITypeFactory typeFactory; private readonly ITypeFactory _typeFactory;
private readonly IPerspexPropertyBinder propertyBinder; private readonly IPerspexPropertyBinder _propertyBinder;
public PerspexTypeRepository(IXamlNamespaceRegistry xamlNamespaceRegistry, public PerspexTypeRepository(IXamlNamespaceRegistry xamlNamespaceRegistry,
ITypeFactory typeFactory, ITypeFactory typeFactory,
ITypeFeatureProvider featureProvider, ITypeFeatureProvider featureProvider,
IPerspexPropertyBinder propertyBinder) : base(xamlNamespaceRegistry, typeFactory, featureProvider) IPerspexPropertyBinder propertyBinder) : base(xamlNamespaceRegistry, typeFactory, featureProvider)
{ {
this.typeFactory = typeFactory; _typeFactory = typeFactory;
this.propertyBinder = propertyBinder; _propertyBinder = propertyBinder;
} }
public override XamlType GetXamlType(Type type) public override XamlType GetXamlType(Type type)
{ {
Guard.ThrowIfNull(type, nameof(type)); Guard.ThrowIfNull(type, nameof(type));
return new PerspexXamlType(type, this, this.typeFactory, this.FeatureProvider, this.propertyBinder); return new PerspexXamlType(type, this, _typeFactory, this.FeatureProvider, _propertyBinder);
} }
} }
} }

47
src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs

@ -1,30 +1,27 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using Glass;
using OmniXaml;
using OmniXaml.Builder;
using OmniXaml.TypeConversion;
using OmniXaml.Typing;
using Perspex.Controls;
using Perspex.Markup.Xaml.Templates;
using Perspex.Markup.Xaml.Converters;
using Perspex.Markup.Xaml.DataBinding;
using Perspex.Markup.Xaml.MarkupExtensions;
using Perspex.Media;
using Perspex.Media.Imaging;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using Controls;
using Converters;
using DataBinding;
using Glass;
using MarkupExtensions;
using Media;
using Media.Imaging;
using OmniXaml;
using OmniXaml.Builder;
using OmniXaml.TypeConversion;
using OmniXaml.Typing;
using Templates;
public class PerspexWiringContext : IWiringContext public class PerspexWiringContext : IWiringContext
{ {
private readonly WiringContext context; private readonly WiringContext _context;
private const string PerspexNs = "https://github.com/grokys/Perspex"; private const string PerspexNs = "https://github.com/grokys/Perspex";
public PerspexWiringContext(ITypeFactory typeFactory) public PerspexWiringContext(ITypeFactory typeFactory)
@ -35,7 +32,7 @@ namespace Perspex.Markup.Xaml.Context
var perspexPropertyBinder = new PerspexPropertyBinder(featureProvider.ConverterProvider); var perspexPropertyBinder = new PerspexPropertyBinder(featureProvider.ConverterProvider);
var xamlTypeRepository = new PerspexTypeRepository(xamlNamespaceRegistry, typeFactory, featureProvider, perspexPropertyBinder); var xamlTypeRepository = new PerspexTypeRepository(xamlNamespaceRegistry, typeFactory, featureProvider, perspexPropertyBinder);
var typeContext = new TypeContext(xamlTypeRepository, xamlNamespaceRegistry, typeFactory); var typeContext = new TypeContext(xamlTypeRepository, xamlNamespaceRegistry, typeFactory);
this.context = new WiringContext(typeContext, featureProvider); _context = new WiringContext(typeContext, featureProvider);
} }
private static XamlNamespaceRegistry CreateXamlNamespaceRegistry() private static XamlNamespaceRegistry CreateXamlNamespaceRegistry()
@ -114,8 +111,8 @@ namespace Perspex.Markup.Xaml.Context
return contentPropertyProvider; return contentPropertyProvider;
} }
public ITypeContext TypeContext => this.context.TypeContext; public ITypeContext TypeContext => _context.TypeContext;
public ITypeFeatureProvider FeatureProvider => this.context.FeatureProvider; public ITypeFeatureProvider FeatureProvider => _context.FeatureProvider;
} }
} }

19
src/Markup/Perspex.Markup.Xaml/Context/PerspexXamlMember.cs

@ -1,18 +1,15 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Markup.Xaml.DataBinding;
using OmniXaml;
using OmniXaml.Typing;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using DataBinding;
using OmniXaml;
using OmniXaml.Typing;
public class PerspexXamlMember : XamlMember public class PerspexXamlMember : XamlMember
{ {
private readonly IPerspexPropertyBinder propertyBinder; private readonly IPerspexPropertyBinder _propertyBinder;
public PerspexXamlMember(string name, public PerspexXamlMember(string name,
XamlType owner, XamlType owner,
@ -21,12 +18,12 @@ namespace Perspex.Markup.Xaml.Context
IPerspexPropertyBinder propertyBinder) IPerspexPropertyBinder propertyBinder)
: base(name, owner, xamlTypeRepository, featureProvider) : base(name, owner, xamlTypeRepository, featureProvider)
{ {
this.propertyBinder = propertyBinder; _propertyBinder = propertyBinder;
} }
protected override IXamlMemberValuePlugin LookupXamlMemberValueConnector() protected override IXamlMemberValuePlugin LookupXamlMemberValueConnector()
{ {
return new PerspexXamlMemberValuePlugin(this, this.propertyBinder); return new PerspexXamlMemberValuePlugin(this, _propertyBinder);
} }
public override string ToString() public override string ToString()

37
src/Markup/Perspex.Markup.Xaml/Context/PerspexXamlMemberValuePlugin.cs

@ -1,27 +1,24 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive.Linq;
using Glass;
using OmniXaml.Typing;
using Perspex.Controls;
using Perspex.Markup.Xaml.DataBinding;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using System;
using System.Reactive.Linq;
using Controls;
using DataBinding;
using Glass;
using OmniXaml.Typing;
public class PerspexXamlMemberValuePlugin : MemberValuePlugin public class PerspexXamlMemberValuePlugin : MemberValuePlugin
{ {
private readonly XamlMember xamlMember; private readonly XamlMember _xamlMember;
private readonly IPerspexPropertyBinder propertyBinder; private readonly IPerspexPropertyBinder _propertyBinder;
public PerspexXamlMemberValuePlugin(XamlMember xamlMember, IPerspexPropertyBinder propertyBinder) : base(xamlMember) public PerspexXamlMemberValuePlugin(XamlMember xamlMember, IPerspexPropertyBinder propertyBinder) : base(xamlMember)
{ {
this.xamlMember = xamlMember; _xamlMember = xamlMember;
this.propertyBinder = propertyBinder; _propertyBinder = propertyBinder;
} }
public override void SetValue(object instance, object value) public override void SetValue(object instance, object value)
@ -63,7 +60,7 @@ namespace Perspex.Markup.Xaml.Context
private void HandleXamlBindingDefinition(XamlBindingDefinition xamlBindingDefinition) private void HandleXamlBindingDefinition(XamlBindingDefinition xamlBindingDefinition)
{ {
PerspexObject subjectObject = xamlBindingDefinition.Target; PerspexObject subjectObject = xamlBindingDefinition.Target;
this.propertyBinder.Create(xamlBindingDefinition); _propertyBinder.Create(xamlBindingDefinition);
var observableForDataContext = subjectObject.GetObservable(Control.DataContextProperty); var observableForDataContext = subjectObject.GetObservable(Control.DataContextProperty);
observableForDataContext.Where(o => o != null).Subscribe(_ => this.BindToDataContextWhenItsSet(xamlBindingDefinition)); observableForDataContext.Where(o => o != null).Subscribe(_ => this.BindToDataContextWhenItsSet(xamlBindingDefinition));
@ -74,7 +71,7 @@ namespace Perspex.Markup.Xaml.Context
var target = definition.Target; var target = definition.Target;
var dataContext = target.DataContext; var dataContext = target.DataContext;
var binding = this.propertyBinder.GetBinding(target, definition.TargetProperty); var binding = _propertyBinder.GetBinding(target, definition.TargetProperty);
binding.BindToDataContext(dataContext); binding.BindToDataContext(dataContext);
} }
@ -83,8 +80,8 @@ namespace Perspex.Markup.Xaml.Context
{ {
get get
{ {
var underlyingType = this.xamlMember.DeclaringType.UnderlyingType; var underlyingType = _xamlMember.DeclaringType.UnderlyingType;
var name = this.xamlMember.Name + "Property"; var name = _xamlMember.Name + "Property";
var value = ReflectionExtensions.GetValueOfStaticField(underlyingType, name); var value = ReflectionExtensions.GetValueOfStaticField(underlyingType, name);
return value as PerspexProperty; return value as PerspexProperty;
@ -100,7 +97,7 @@ namespace Perspex.Markup.Xaml.Context
public override string ToString() public override string ToString()
{ {
return $"{{Perspex Value Connector for member {this.xamlMember}}}"; return $"{{Perspex Value Connector for member {_xamlMember}}}";
} }
} }
} }

23
src/Markup/Perspex.Markup.Xaml/Context/PerspexXamlType.cs

@ -1,19 +1,16 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using OmniXaml;
using OmniXaml.Typing;
using Perspex.Markup.Xaml.DataBinding;
namespace Perspex.Markup.Xaml.Context namespace Perspex.Markup.Xaml.Context
{ {
using System;
using DataBinding;
using OmniXaml;
using OmniXaml.Typing;
public class PerspexXamlType : XamlType public class PerspexXamlType : XamlType
{ {
private readonly IPerspexPropertyBinder propertyBinder; private readonly IPerspexPropertyBinder _propertyBinder;
public PerspexXamlType(Type type, public PerspexXamlType(Type type,
IXamlTypeRepository typeRepository, IXamlTypeRepository typeRepository,
@ -21,14 +18,14 @@ namespace Perspex.Markup.Xaml.Context
ITypeFeatureProvider featureProvider, ITypeFeatureProvider featureProvider,
IPerspexPropertyBinder propertyBinder) : base(type, typeRepository, typeFactory, featureProvider) IPerspexPropertyBinder propertyBinder) : base(type, typeRepository, typeFactory, featureProvider)
{ {
this.propertyBinder = propertyBinder; _propertyBinder = propertyBinder;
} }
protected IPerspexPropertyBinder PropertyBinder => this.propertyBinder; protected IPerspexPropertyBinder PropertyBinder => _propertyBinder;
protected override XamlMember LookupMember(string name) protected override XamlMember LookupMember(string name)
{ {
return new PerspexXamlMember(name, this, this.TypeRepository, this.FeatureProvider, this.propertyBinder); return new PerspexXamlMember(name, this, this.TypeRepository, this.FeatureProvider, _propertyBinder);
} }
public override string ToString() public override string ToString()

15
src/Markup/Perspex.Markup.Xaml/Converters/BitmapConverter.cs

@ -1,16 +1,13 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using Perspex.Media.Imaging;
namespace Perspex.Markup.Xaml.Converters namespace Perspex.Markup.Xaml.Converters
{ {
using System;
using System.Globalization;
using Media.Imaging;
using OmniXaml.TypeConversion;
public class BitmapConverter : ITypeConverter public class BitmapConverter : ITypeConverter
{ {
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType) public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)

15
src/Markup/Perspex.Markup.Xaml/Converters/BrushConverter.cs

@ -1,16 +1,13 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using Perspex.Media;
namespace Perspex.Markup.Xaml.Converters namespace Perspex.Markup.Xaml.Converters
{ {
using System;
using System.Globalization;
using Media;
using OmniXaml.TypeConversion;
public class BrushConverter : ITypeConverter public class BrushConverter : ITypeConverter
{ {
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType) public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)

15
src/Markup/Perspex.Markup.Xaml/Converters/ColumnDefinitionsTypeConverter.cs

@ -1,16 +1,13 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using Perspex.Controls;
namespace Perspex.Markup.Xaml.Converters namespace Perspex.Markup.Xaml.Converters
{ {
using System;
using System.Globalization;
using Controls;
using OmniXaml.TypeConversion;
public class ColumnDefinitionsTypeConverter : ITypeConverter public class ColumnDefinitionsTypeConverter : ITypeConverter
{ {
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType) public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)

15
src/Markup/Perspex.Markup.Xaml/Converters/GridLengthTypeConverter.cs

@ -1,16 +1,13 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using Perspex.Controls;
namespace Perspex.Markup.Xaml.Converters namespace Perspex.Markup.Xaml.Converters
{ {
using System;
using System.Globalization;
using Controls;
using OmniXaml.TypeConversion;
public class GridLengthTypeConverter : ITypeConverter public class GridLengthTypeConverter : ITypeConverter
{ {
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType) public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)

15
src/Markup/Perspex.Markup.Xaml/Converters/RowDefinitionsTypeConverter.cs

@ -1,16 +1,13 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using Perspex.Controls;
namespace Perspex.Markup.Xaml.Converters namespace Perspex.Markup.Xaml.Converters
{ {
using System;
using System.Globalization;
using Controls;
using OmniXaml.TypeConversion;
public class RowDefinitionsTypeConverter : ITypeConverter public class RowDefinitionsTypeConverter : ITypeConverter
{ {
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType) public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)

13
src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs

@ -1,15 +1,12 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
namespace Perspex.Markup.Xaml.Converters namespace Perspex.Markup.Xaml.Converters
{ {
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
public class ThicknessConverter : ITypeConverter public class ThicknessConverter : ITypeConverter
{ {
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType) public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)

47
src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/ObservablePropertyBranch.cs

@ -1,33 +1,30 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
using Glass;
namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
{ {
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
using Glass;
public class ObservablePropertyBranch public class ObservablePropertyBranch
{ {
private readonly object instance; private readonly object _instance;
private readonly PropertyPath propertyPath; private readonly PropertyPath _propertyPath;
private readonly PropertyMountPoint mountPoint; private readonly PropertyMountPoint _mountPoint;
public ObservablePropertyBranch(object instance, PropertyPath propertyPath) public ObservablePropertyBranch(object instance, PropertyPath propertyPath)
{ {
Guard.ThrowIfNull(instance, nameof(instance)); Guard.ThrowIfNull(instance, nameof(instance));
Guard.ThrowIfNull(propertyPath, nameof(propertyPath)); Guard.ThrowIfNull(propertyPath, nameof(propertyPath));
this.instance = instance; _instance = instance;
this.propertyPath = propertyPath; _propertyPath = propertyPath;
this.mountPoint = new PropertyMountPoint(instance, propertyPath); _mountPoint = new PropertyMountPoint(instance, propertyPath);
var properties = this.GetPropertiesThatRaiseNotifications(); var properties = this.GetPropertiesThatRaiseNotifications();
this.Values = this.CreateUnifiedObservableFromNodes(properties); this.Values = this.CreateUnifiedObservableFromNodes(properties);
} }
@ -45,12 +42,12 @@ namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
parentOnPropertyChanged => subscription.Parent.PropertyChanged += parentOnPropertyChanged, parentOnPropertyChanged => subscription.Parent.PropertyChanged += parentOnPropertyChanged,
parentOnPropertyChanged => subscription.Parent.PropertyChanged -= parentOnPropertyChanged) parentOnPropertyChanged => subscription.Parent.PropertyChanged -= parentOnPropertyChanged)
.Where(pattern => pattern.EventArgs.PropertyName == subscription.PropertyName) .Where(pattern => pattern.EventArgs.PropertyName == subscription.PropertyName)
.Select(pattern => this.mountPoint.Value); .Select(pattern => _mountPoint.Value);
} }
private IEnumerable<PropertyDefinition> GetPropertiesThatRaiseNotifications() private IEnumerable<PropertyDefinition> GetPropertiesThatRaiseNotifications()
{ {
return this.GetSubscriptionsRecursive(this.instance, this.propertyPath, 0); return this.GetSubscriptionsRecursive(_instance, _propertyPath, 0);
} }
private IEnumerable<PropertyDefinition> GetSubscriptionsRecursive(object current, PropertyPath propertyPath, int i) private IEnumerable<PropertyDefinition> GetSubscriptionsRecursive(object current, PropertyPath propertyPath, int i)
@ -66,13 +63,13 @@ namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
var nextPropertyName = propertyPath.Chunks[i]; var nextPropertyName = propertyPath.Chunks[i];
subscriptions.Add(new PropertyDefinition(inpc, nextPropertyName)); subscriptions.Add(new PropertyDefinition(inpc, nextPropertyName));
if (i < this.propertyPath.Chunks.Length) if (i < _propertyPath.Chunks.Length)
{ {
var currentObjectTypeInfo = current.GetType().GetTypeInfo(); var currentObjectTypeInfo = current.GetType().GetTypeInfo();
var nextProperty = currentObjectTypeInfo.GetDeclaredProperty(nextPropertyName); var nextProperty = currentObjectTypeInfo.GetDeclaredProperty(nextPropertyName);
var nextInstance = nextProperty.GetValue(current); var nextInstance = nextProperty.GetValue(current);
if (i < this.propertyPath.Chunks.Length - 1) if (i < _propertyPath.Chunks.Length - 1)
{ {
subscriptions.AddRange(this.GetSubscriptionsRecursive(nextInstance, propertyPath, i + 1)); subscriptions.AddRange(this.GetSubscriptionsRecursive(nextInstance, propertyPath, i + 1));
} }
@ -85,16 +82,16 @@ namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
{ {
get get
{ {
return this.mountPoint.Value; return _mountPoint.Value;
} }
set set
{ {
this.mountPoint.Value = value; _mountPoint.Value = value;
} }
} }
public Type Type => this.mountPoint.ProperyType; public Type Type => _mountPoint.ProperyType;
private class PropertyDefinition private class PropertyDefinition
{ {

23
src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/PropertyMountPoint.cs

@ -1,25 +1,22 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reflection;
using Glass;
namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
{ {
using System;
using System.Reflection;
using Glass;
public class PropertyMountPoint public class PropertyMountPoint
{ {
private readonly TargettedProperty referencedTargettedProperty; private readonly TargettedProperty _referencedTargettedProperty;
public PropertyMountPoint(object origin, PropertyPath propertyPath) public PropertyMountPoint(object origin, PropertyPath propertyPath)
{ {
Guard.ThrowIfNull(origin, nameof(origin)); Guard.ThrowIfNull(origin, nameof(origin));
Guard.ThrowIfNull(propertyPath, nameof(propertyPath)); Guard.ThrowIfNull(propertyPath, nameof(propertyPath));
this.referencedTargettedProperty = GetReferencedPropertyInfo(origin, propertyPath, 0); _referencedTargettedProperty = GetReferencedPropertyInfo(origin, propertyPath, 0);
} }
private static TargettedProperty GetReferencedPropertyInfo(object current, PropertyPath propertyPath, int level) private static TargettedProperty GetReferencedPropertyInfo(object current, PropertyPath propertyPath, int level)
@ -41,15 +38,15 @@ namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
{ {
get get
{ {
return this.referencedTargettedProperty.Value; return _referencedTargettedProperty.Value;
} }
set set
{ {
this.referencedTargettedProperty.Value = value; _referencedTargettedProperty.Value = value;
} }
} }
public Type ProperyType => this.referencedTargettedProperty.PropertyType; public Type ProperyType => _referencedTargettedProperty.PropertyType;
} }
} }

19
src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/PropertyPath.cs

@ -1,29 +1,26 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
{ {
public class PropertyPath public class PropertyPath
{ {
private string[] chunks; private string[] _chunks;
private PropertyPath(PropertyPath propertyPath) private PropertyPath(PropertyPath propertyPath)
{ {
this.chunks = propertyPath.Chunks; _chunks = propertyPath.Chunks;
} }
public PropertyPath(string path) public PropertyPath(string path)
{ {
this.chunks = path.Split('.'); _chunks = path.Split('.');
} }
public string[] Chunks public string[] Chunks
{ {
get { return this.chunks; } get { return _chunks; }
set { this.chunks = value; } set { _chunks = value; }
} }
public PropertyPath Clone() public PropertyPath Clone()
@ -33,7 +30,7 @@ namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
public override string ToString() public override string ToString()
{ {
return string.Join(".", this.chunks); return string.Join(".", _chunks);
} }
} }
} }

29
src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/TargettedProperty.cs

@ -1,44 +1,41 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reflection;
using Glass;
namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking namespace Perspex.Markup.Xaml.DataBinding.ChangeTracking
{ {
using System;
using System.Reflection;
using Glass;
internal class TargettedProperty internal class TargettedProperty
{ {
private readonly object instance; private readonly object _instance;
private readonly PropertyInfo propertyInfo; private readonly PropertyInfo _propertyInfo;
public TargettedProperty(object instance, PropertyInfo propertyInfo) public TargettedProperty(object instance, PropertyInfo propertyInfo)
{ {
Guard.ThrowIfNull(instance, nameof(instance)); Guard.ThrowIfNull(instance, nameof(instance));
Guard.ThrowIfNull(propertyInfo, nameof(propertyInfo)); Guard.ThrowIfNull(propertyInfo, nameof(propertyInfo));
this.instance = instance; _instance = instance;
this.propertyInfo = propertyInfo; _propertyInfo = propertyInfo;
} }
public object Value public object Value
{ {
get get
{ {
return this.propertyInfo.GetValue(this.instance); return _propertyInfo.GetValue(_instance);
} }
set set
{ {
this.propertyInfo.SetValue(this.instance, value); _propertyInfo.SetValue(_instance, value);
} }
} }
public Type PropertyType => this.propertyInfo.PropertyType; public Type PropertyType => _propertyInfo.PropertyType;
public string Name => this.propertyInfo.Name; public string Name => _propertyInfo.Name;
} }
} }

87
src/Markup/Perspex.Markup.Xaml/DataBinding/DataContextChangeSynchronizer.cs

@ -1,98 +1,95 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using System.Reactive.Linq;
using System.Reflection;
using Glass;
using OmniXaml.TypeConversion;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
using System;
using System.Globalization;
using System.Reactive.Linq;
using System.Reflection;
using ChangeTracking;
using Glass;
using OmniXaml.TypeConversion;
public class DataContextChangeSynchronizer public class DataContextChangeSynchronizer
{ {
private readonly BindingTarget bindingTarget; private readonly BindingTarget _bindingTarget;
private readonly ITypeConverter targetPropertyTypeConverter; private readonly ITypeConverter _targetPropertyTypeConverter;
private readonly TargetBindingEndpoint bindingEndpoint; private readonly TargetBindingEndpoint _bindingEndpoint;
private readonly ObservablePropertyBranch sourceEndpoint; private readonly ObservablePropertyBranch _sourceEndpoint;
public DataContextChangeSynchronizer(BindingSource bindingSource, BindingTarget bindingTarget, ITypeConverterProvider typeConverterProvider) public DataContextChangeSynchronizer(BindingSource bindingSource, BindingTarget bindingTarget, ITypeConverterProvider typeConverterProvider)
{ {
this.bindingTarget = bindingTarget; _bindingTarget = bindingTarget;
Guard.ThrowIfNull(bindingTarget.Object, nameof(bindingTarget.Object)); Guard.ThrowIfNull(bindingTarget.Object, nameof(bindingTarget.Object));
Guard.ThrowIfNull(bindingTarget.Property, nameof(bindingTarget.Property)); Guard.ThrowIfNull(bindingTarget.Property, nameof(bindingTarget.Property));
Guard.ThrowIfNull(bindingSource.SourcePropertyPath, nameof(bindingSource.SourcePropertyPath)); Guard.ThrowIfNull(bindingSource.SourcePropertyPath, nameof(bindingSource.SourcePropertyPath));
Guard.ThrowIfNull(bindingSource.Source, nameof(bindingSource.Source)); Guard.ThrowIfNull(bindingSource.Source, nameof(bindingSource.Source));
Guard.ThrowIfNull(typeConverterProvider, nameof(typeConverterProvider)); Guard.ThrowIfNull(typeConverterProvider, nameof(typeConverterProvider));
this.bindingEndpoint = new TargetBindingEndpoint(bindingTarget.Object, bindingTarget.Property); _bindingEndpoint = new TargetBindingEndpoint(bindingTarget.Object, bindingTarget.Property);
this.sourceEndpoint = new ObservablePropertyBranch(bindingSource.Source, bindingSource.SourcePropertyPath); _sourceEndpoint = new ObservablePropertyBranch(bindingSource.Source, bindingSource.SourcePropertyPath);
this.targetPropertyTypeConverter = typeConverterProvider.GetTypeConverter(bindingTarget.Property.PropertyType); _targetPropertyTypeConverter = typeConverterProvider.GetTypeConverter(bindingTarget.Property.PropertyType);
} }
public class BindingTarget public class BindingTarget
{ {
private readonly PerspexObject obj; private readonly PerspexObject _obj;
private readonly PerspexProperty property; private readonly PerspexProperty _property;
public BindingTarget(PerspexObject @object, PerspexProperty property) public BindingTarget(PerspexObject @object, PerspexProperty property)
{ {
this.obj = @object; _obj = @object;
this.property = property; _property = property;
} }
public PerspexObject Object => obj; public PerspexObject Object => _obj;
public PerspexProperty Property => property; public PerspexProperty Property => _property;
public object Value public object Value
{ {
get { return obj.GetValue(property); } get { return _obj.GetValue(_property); }
set { obj.SetValue(property, value); } set { _obj.SetValue(_property, value); }
} }
} }
public class BindingSource public class BindingSource
{ {
private readonly PropertyPath sourcePropertyPath; private readonly PropertyPath _sourcePropertyPath;
private readonly object source; private readonly object _source;
public BindingSource(PropertyPath sourcePropertyPath, object source) public BindingSource(PropertyPath sourcePropertyPath, object source)
{ {
this.sourcePropertyPath = sourcePropertyPath; _sourcePropertyPath = sourcePropertyPath;
this.source = source; _source = source;
} }
public PropertyPath SourcePropertyPath => this.sourcePropertyPath; public PropertyPath SourcePropertyPath => _sourcePropertyPath;
public object Source => source; public object Source => _source;
} }
public void StartUpdatingTargetWhenSourceChanges() public void StartUpdatingTargetWhenSourceChanges()
{ {
// TODO: commenting out this line will make the existing value to be skipped from the SourceValues. This is not supposed to happen. Is it? // TODO: commenting out this line will make the existing value to be skipped from the SourceValues. This is not supposed to happen. Is it?
bindingTarget.Value = ConvertedValue(sourceEndpoint.Value, bindingTarget.Property.PropertyType); _bindingTarget.Value = ConvertedValue(_sourceEndpoint.Value, _bindingTarget.Property.PropertyType);
// We use the native Bind method from PerspexObject to subscribe to the SourceValues observable // We use the native Bind method from PerspexObject to subscribe to the SourceValues observable
this.bindingTarget.Object.Bind(this.bindingTarget.Property, this.SourceValues); _bindingTarget.Object.Bind(_bindingTarget.Property, this.SourceValues);
} }
public void StartUpdatingSourceWhenTargetChanges() public void StartUpdatingSourceWhenTargetChanges()
{ {
// We subscribe to the TargetValues and each time we have a new value, we update the source with it // We subscribe to the TargetValues and each time we have a new value, we update the source with it
this.TargetValues.Subscribe(newValue => this.sourceEndpoint.Value = newValue); this.TargetValues.Subscribe(newValue => _sourceEndpoint.Value = newValue);
} }
private IObservable<object> SourceValues private IObservable<object> SourceValues
{ {
get get
{ {
return this.sourceEndpoint.Values.Select(originalValue => this.ConvertedValue(originalValue, this.bindingTarget.Property.PropertyType)); return _sourceEndpoint.Values.Select(originalValue => this.ConvertedValue(originalValue, _bindingTarget.Property.PropertyType));
} }
} }
@ -100,8 +97,8 @@ namespace Perspex.Markup.Xaml.DataBinding
{ {
get get
{ {
return this.bindingEndpoint.Object return _bindingEndpoint.Object
.GetObservable(this.bindingEndpoint.Property).Select(o => this.ConvertedValue(o, this.sourceEndpoint.Type)); .GetObservable(_bindingEndpoint.Property).Select(o => this.ConvertedValue(o, _sourceEndpoint.Type));
} }
} }
@ -109,8 +106,8 @@ namespace Perspex.Markup.Xaml.DataBinding
{ {
get get
{ {
var sourceTypeInfo = this.sourceEndpoint.Type.GetTypeInfo(); var sourceTypeInfo = _sourceEndpoint.Type.GetTypeInfo();
var targetTypeInfo = this.bindingEndpoint.Property.PropertyType.GetTypeInfo(); var targetTypeInfo = _bindingEndpoint.Property.PropertyType.GetTypeInfo();
var compatible = targetTypeInfo.IsAssignableFrom(sourceTypeInfo); var compatible = targetTypeInfo.IsAssignableFrom(sourceTypeInfo);
return compatible; return compatible;
} }
@ -137,11 +134,11 @@ namespace Perspex.Markup.Xaml.DataBinding
return true; return true;
} }
if (this.targetPropertyTypeConverter != null) if (_targetPropertyTypeConverter != null)
{ {
if (this.targetPropertyTypeConverter.CanConvertTo(null, targetType)) if (_targetPropertyTypeConverter.CanConvertTo(null, targetType))
{ {
object convertedValue = this.targetPropertyTypeConverter.ConvertTo( object convertedValue = _targetPropertyTypeConverter.ConvertTo(
null, null,
CultureInfo.InvariantCulture, CultureInfo.InvariantCulture,
originalValue, originalValue,

9
src/Markup/Perspex.Markup.Xaml/DataBinding/IPerspexPropertyBinder.cs

@ -1,13 +1,10 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
using System.Collections.Generic;
public interface IPerspexPropertyBinder public interface IPerspexPropertyBinder
{ {
XamlBinding GetBinding(PerspexObject po, PerspexProperty pp); XamlBinding GetBinding(PerspexObject po, PerspexProperty pp);

31
src/Markup/Perspex.Markup.Xaml/DataBinding/PerspexPropertyBinder.cs

@ -1,36 +1,33 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using OmniXaml.TypeConversion;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
using System;
using System.Collections.Generic;
using System.Linq;
using OmniXaml.TypeConversion;
public class PerspexPropertyBinder : IPerspexPropertyBinder public class PerspexPropertyBinder : IPerspexPropertyBinder
{ {
private readonly ITypeConverterProvider typeConverterProvider; private readonly ITypeConverterProvider _typeConverterProvider;
private readonly HashSet<XamlBinding> bindings; private readonly HashSet<XamlBinding> _bindings;
public PerspexPropertyBinder(ITypeConverterProvider typeConverterProvider) public PerspexPropertyBinder(ITypeConverterProvider typeConverterProvider)
{ {
this.typeConverterProvider = typeConverterProvider; _typeConverterProvider = typeConverterProvider;
this.bindings = new HashSet<XamlBinding>(); _bindings = new HashSet<XamlBinding>();
} }
public XamlBinding GetBinding(PerspexObject po, PerspexProperty pp) public XamlBinding GetBinding(PerspexObject po, PerspexProperty pp)
{ {
return this.bindings.First(xamlBinding => xamlBinding.Target == po && xamlBinding.TargetProperty == pp); return _bindings.First(xamlBinding => xamlBinding.Target == po && xamlBinding.TargetProperty == pp);
} }
public IEnumerable<XamlBinding> GetBindings(PerspexObject source) public IEnumerable<XamlBinding> GetBindings(PerspexObject source)
{ {
return from binding in this.bindings return from binding in _bindings
where binding.Target == source where binding.Target == source
select binding; select binding;
} }
@ -47,7 +44,7 @@ namespace Perspex.Markup.Xaml.DataBinding
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
var binding = new XamlBinding(this.typeConverterProvider) var binding = new XamlBinding(_typeConverterProvider)
{ {
BindingMode = xamlBinding.BindingMode, BindingMode = xamlBinding.BindingMode,
SourcePropertyPath = xamlBinding.SourcePropertyPath, SourcePropertyPath = xamlBinding.SourcePropertyPath,
@ -55,7 +52,7 @@ namespace Perspex.Markup.Xaml.DataBinding
TargetProperty = xamlBinding.TargetProperty TargetProperty = xamlBinding.TargetProperty
}; };
this.bindings.Add(binding); _bindings.Add(binding);
return binding; return binding;
} }
} }

11
src/Markup/Perspex.Markup.Xaml/DataBinding/SourceBindingEndpoint.cs

@ -1,14 +1,11 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.ComponentModel;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
using System;
using System.ComponentModel;
public class SourceBindingEndpoint public class SourceBindingEndpoint
{ {
public Type PropertyType { get; } public Type PropertyType { get; }

7
src/Markup/Perspex.Markup.Xaml/DataBinding/TargetBindingEndpoint.cs

@ -1,8 +1,5 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {

31
src/Markup/Perspex.Markup.Xaml/DataBinding/XamlBinding.cs

@ -1,24 +1,21 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Diagnostics;
using OmniXaml.TypeConversion;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
using System;
using System.Diagnostics;
using ChangeTracking;
using OmniXaml.TypeConversion;
public class XamlBinding public class XamlBinding
{ {
private readonly ITypeConverterProvider typeConverterProvider; private readonly ITypeConverterProvider _typeConverterProvider;
private DataContextChangeSynchronizer changeSynchronizer; private DataContextChangeSynchronizer _changeSynchronizer;
public XamlBinding(ITypeConverterProvider typeConverterProvider) public XamlBinding(ITypeConverterProvider typeConverterProvider)
{ {
this.typeConverterProvider = typeConverterProvider; _typeConverterProvider = typeConverterProvider;
} }
public PerspexObject Target { get; set; } public PerspexObject Target { get; set; }
@ -41,22 +38,22 @@ namespace Perspex.Markup.Xaml.DataBinding
var bindingSource = new DataContextChangeSynchronizer.BindingSource(this.SourcePropertyPath, dataContext); var bindingSource = new DataContextChangeSynchronizer.BindingSource(this.SourcePropertyPath, dataContext);
var bindingTarget = new DataContextChangeSynchronizer.BindingTarget(this.Target, this.TargetProperty); var bindingTarget = new DataContextChangeSynchronizer.BindingTarget(this.Target, this.TargetProperty);
this.changeSynchronizer = new DataContextChangeSynchronizer(bindingSource, bindingTarget, this.typeConverterProvider); _changeSynchronizer = new DataContextChangeSynchronizer(bindingSource, bindingTarget, _typeConverterProvider);
if (this.BindingMode == BindingMode.TwoWay) if (this.BindingMode == BindingMode.TwoWay)
{ {
this.changeSynchronizer.StartUpdatingTargetWhenSourceChanges(); _changeSynchronizer.StartUpdatingTargetWhenSourceChanges();
this.changeSynchronizer.StartUpdatingSourceWhenTargetChanges(); _changeSynchronizer.StartUpdatingSourceWhenTargetChanges();
} }
if (this.BindingMode == BindingMode.OneWay) if (this.BindingMode == BindingMode.OneWay)
{ {
this.changeSynchronizer.StartUpdatingTargetWhenSourceChanges(); _changeSynchronizer.StartUpdatingTargetWhenSourceChanges();
} }
if (this.BindingMode == BindingMode.OneWayToSource) if (this.BindingMode == BindingMode.OneWayToSource)
{ {
this.changeSynchronizer.StartUpdatingSourceWhenTargetChanges(); _changeSynchronizer.StartUpdatingSourceWhenTargetChanges();
} }
} }
catch (Exception e) catch (Exception e)

35
src/Markup/Perspex.Markup.Xaml/DataBinding/XamlBindingDefinition.cs

@ -1,35 +1,32 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Controls;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
using ChangeTracking;
using Controls;
public class XamlBindingDefinition public class XamlBindingDefinition
{ {
private PropertyPath sourcePropertyPath; private PropertyPath _sourcePropertyPath;
private BindingMode bindingMode; private BindingMode _bindingMode;
private readonly Control target; private readonly Control _target;
private readonly PerspexProperty targetProperty; private readonly PerspexProperty _targetProperty;
public XamlBindingDefinition(Control target, PerspexProperty targetProperty, PropertyPath sourcePropertyPath, BindingMode bindingMode) public XamlBindingDefinition(Control target, PerspexProperty targetProperty, PropertyPath sourcePropertyPath, BindingMode bindingMode)
{ {
this.target = target; _target = target;
this.targetProperty = targetProperty; _targetProperty = targetProperty;
this.sourcePropertyPath = sourcePropertyPath; _sourcePropertyPath = sourcePropertyPath;
this.bindingMode = bindingMode; _bindingMode = bindingMode;
} }
public Control Target => this.target; public Control Target => _target;
public PerspexProperty TargetProperty => this.targetProperty; public PerspexProperty TargetProperty => _targetProperty;
public PropertyPath SourcePropertyPath => this.sourcePropertyPath; public PropertyPath SourcePropertyPath => _sourcePropertyPath;
public BindingMode BindingMode => this.bindingMode; public BindingMode BindingMode => _bindingMode;
} }
} }

17
src/Markup/Perspex.Markup.Xaml/MarkupExtensions/BindingExtension.cs

@ -1,17 +1,14 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Linq;
using OmniXaml;
using Perspex.Controls;
using Perspex.Markup.Xaml.DataBinding;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Markup.Xaml.MarkupExtensions namespace Perspex.Markup.Xaml.MarkupExtensions
{ {
using System.Linq;
using Controls;
using DataBinding;
using DataBinding.ChangeTracking;
using OmniXaml;
public class BindingExtension : MarkupExtension public class BindingExtension : MarkupExtension
{ {
public BindingExtension() public BindingExtension()

17
src/Markup/Perspex.Markup.Xaml/MarkupExtensions/TypeExtension.cs

@ -1,17 +1,14 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Glass;
using OmniXaml;
using OmniXaml.Attributes;
using OmniXaml.Typing;
namespace Perspex.Markup.Xaml.MarkupExtensions namespace Perspex.Markup.Xaml.MarkupExtensions
{ {
using System;
using Glass;
using OmniXaml;
using OmniXaml.Attributes;
using OmniXaml.Typing;
[ContentProperty("TargetType")] [ContentProperty("TargetType")]
public class TypeExtension : MarkupExtension public class TypeExtension : MarkupExtension
{ {

19
src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs

@ -1,18 +1,15 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reflection;
using OmniXaml;
using Perspex.Markup.Xaml.Context;
using Perspex.Platform;
using Splat;
namespace Perspex.Markup.Xaml namespace Perspex.Markup.Xaml
{ {
using System;
using System.Reflection;
using OmniXaml;
using Perspex.Markup.Xaml.Context;
using Platform;
using Splat;
/// <summary> /// <summary>
/// Loads XAML for a perspex application. /// Loads XAML for a perspex application.
/// </summary> /// </summary>

7
src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs

@ -1,8 +1,5 @@
 // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection; using System.Reflection;

7
src/Markup/Perspex.Markup.Xaml/Templates/Template.cs

@ -1,8 +1,5 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Perspex.Markup.Xaml.Templates namespace Perspex.Markup.Xaml.Templates
{ {

27
src/Markup/Perspex.Markup.Xaml/Templates/TemplateContent.cs

@ -1,32 +1,29 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using OmniXaml;
using Perspex.Controls;
using Perspex.Markup.Xaml.Context;
namespace Perspex.Markup.Xaml.Templates namespace Perspex.Markup.Xaml.Templates
{ {
using System.Collections.Generic;
using Context;
using OmniXaml;
using Perspex.Controls;
public class TemplateContent public class TemplateContent
{ {
private readonly IEnumerable<XamlInstruction> nodes; private readonly IEnumerable<XamlInstruction> _nodes;
private readonly IWiringContext context; private readonly IWiringContext _context;
public TemplateContent(IEnumerable<XamlInstruction> nodes, IWiringContext context) public TemplateContent(IEnumerable<XamlInstruction> nodes, IWiringContext context)
{ {
this.nodes = nodes; _nodes = nodes;
this.context = context; _context = context;
} }
public Control Load() public Control Load()
{ {
var assembler = new PerspexObjectAssembler(this.context); var assembler = new PerspexObjectAssembler(_context);
foreach (var xamlNode in this.nodes) foreach (var xamlNode in _nodes)
{ {
assembler.Process(xamlNode); assembler.Process(xamlNode);
} }

11
src/Markup/Perspex.Markup.Xaml/Templates/TemplateLoader.cs

@ -1,14 +1,11 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using OmniXaml;
namespace Perspex.Markup.Xaml.Templates namespace Perspex.Markup.Xaml.Templates
{ {
using System.Collections.Generic;
using OmniXaml;
public class TemplateLoader : IDeferredLoader public class TemplateLoader : IDeferredLoader
{ {
public object Load(IEnumerable<XamlInstruction> nodes, IWiringContext context) public object Load(IEnumerable<XamlInstruction> nodes, IWiringContext context)

15
src/Markup/Perspex.Markup.Xaml/Templates/XamlDataTemplate.cs

@ -1,16 +1,13 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using OmniXaml.Attributes;
using Perspex.Controls;
using Perspex.Controls.Templates;
namespace Perspex.Markup.Xaml.Templates namespace Perspex.Markup.Xaml.Templates
{ {
using System;
using Controls.Templates;
using OmniXaml.Attributes;
using Perspex.Controls;
[ContentProperty("Content")] [ContentProperty("Content")]
public class XamlDataTemplate : IDataTemplate public class XamlDataTemplate : IDataTemplate
{ {

5
src/NGenerics/Constants.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -9,7 +12,7 @@
namespace NGenerics namespace NGenerics
{ {
static class Constants internal static class Constants
{ {
public const string NotEnoughSpaceInTheTargetArray = "Not enough space in the target array."; public const string NotEnoughSpaceInTheTargetArray = "Not enough space in the target array.";
} }

74
src/NGenerics/DataStructures/Comparers/ComparisonComparer.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -20,59 +23,58 @@ namespace NGenerics.Comparers
/// <typeparam name="T">The type of the objects to compare.</typeparam> /// <typeparam name="T">The type of the objects to compare.</typeparam>
//[Serializable] //[Serializable]
public sealed class ComparisonComparer<T> : IComparer<T> public sealed class ComparisonComparer<T> : IComparer<T>
{ {
#region Globals #region Globals
private Comparison<T> _comparison;
private Comparison<T> comparison; #endregion
#endregion #region Construction
#region Construction
/// <param name="comparison">The comparison.</param> /// <param name="comparison">The comparison.</param>
/// <exception cref="ArgumentNullException"><paramref name="comparison"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception> /// <exception cref="ArgumentNullException"><paramref name="comparison"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
public ComparisonComparer(Comparison<T> comparison) public ComparisonComparer(Comparison<T> comparison)
{ {
Guard.ArgumentNotNull(comparison, "comparison"); Guard.ArgumentNotNull(comparison, "comparison");
this.comparison = comparison; _comparison = comparison;
} }
#endregion #endregion
#region Public Members #region Public Members
/// <summary> /// <summary>
/// Gets or sets the comparison used in this comparer. /// Gets or sets the comparison used in this comparer.
/// </summary> /// </summary>
/// <value>The comparison used in this comparer.</value> /// <value>The comparison used in this comparer.</value>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception> /// <exception cref="ArgumentNullException"><paramref name="value"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
public Comparison<T> Comparison public Comparison<T> Comparison
{ {
get get
{ {
return comparison; return _comparison;
} }
set set
{ {
Guard.ArgumentNotNull(value, "value"); Guard.ArgumentNotNull(value, "value");
comparison = value; _comparison = value;
} }
} }
#endregion #endregion
#region IComparer<T> Members #region IComparer<T> Members
/// <inheritdoc /> /// <inheritdoc />
public int Compare(T x, T y) public int Compare(T x, T y)
{ {
return comparison(x, y); return _comparison(x, y);
} }
#endregion #endregion
} }
} }

41
src/NGenerics/DataStructures/Comparers/KeyValuePairComparer.cs

@ -1,4 +1,7 @@
/* // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -11,18 +14,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace NGenerics.Comparers { namespace NGenerics.Comparers
{
/// <summary> /// <summary>
/// A comparer for comparing keys for the KeyValuePair class. /// A comparer for comparing keys for the KeyValuePair class.
/// </summary> /// </summary>
/// <typeparam name="TKey">The key type.</typeparam> /// <typeparam name="TKey">The key type.</typeparam>
/// <typeparam name="TValue">The value type.</typeparam> /// <typeparam name="TValue">The value type.</typeparam>
//[Serializable] //[Serializable]
public class KeyValuePairComparer<TKey, TValue> : IComparer<KeyValuePair<TKey, TValue>> { public class KeyValuePairComparer<TKey, TValue> : IComparer<KeyValuePair<TKey, TValue>>
{
#region Globals #region Globals
private readonly IComparer<TKey> comparer; private readonly IComparer<TKey> _comparer;
#endregion #endregion
@ -31,22 +35,23 @@ namespace NGenerics.Comparers {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="KeyValuePairComparer&lt;TKey, TValue&gt;"/> class. /// Initializes a new instance of the <see cref="KeyValuePairComparer&lt;TKey, TValue&gt;"/> class.
/// </summary> /// </summary>
public KeyValuePairComparer() { public KeyValuePairComparer()
comparer = Comparer<TKey>.Default; {
_comparer = Comparer<TKey>.Default;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="KeyValuePairComparer&lt;TKey, TValue&gt;"/> class. /// Initializes a new instance of the <see cref="KeyValuePairComparer&lt;TKey, TValue&gt;"/> class.
/// </summary> /// </summary>
/// <param name="comparer">The comparer.</param> /// <param name="comparer">The comparer.</param>
public KeyValuePairComparer(IComparer<TKey> comparer) { public KeyValuePairComparer(IComparer<TKey> comparer)
{
if (comparer == null) if (comparer == null)
{ {
throw new ArgumentNullException("comparer"); throw new ArgumentNullException("comparer");
} }
this.comparer = comparer; _comparer = comparer;
} }
/// <summary> /// <summary>
@ -55,11 +60,12 @@ namespace NGenerics.Comparers {
/// <param name="comparison">The comparison.</param> /// <param name="comparison">The comparison.</param>
public KeyValuePairComparer(Comparison<TKey> comparison) public KeyValuePairComparer(Comparison<TKey> comparison)
{ {
if (comparison == null) { if (comparison == null)
{
throw new ArgumentNullException("comparison"); throw new ArgumentNullException("comparison");
} }
comparer = new ComparisonComparer<TKey>(comparison); _comparer = new ComparisonComparer<TKey>(comparison);
} }
#endregion #endregion
@ -67,8 +73,9 @@ namespace NGenerics.Comparers {
#region IComparer<KeyValuePairComparer<TKey,TValue>> Members #region IComparer<KeyValuePairComparer<TKey,TValue>> Members
/// <inheritdoc /> /// <inheritdoc />
public int Compare(KeyValuePair<TKey, TValue> x, KeyValuePair<TKey, TValue> y) { public int Compare(KeyValuePair<TKey, TValue> x, KeyValuePair<TKey, TValue> y)
return comparer.Compare(x.Key, y.Key); {
return _comparer.Compare(x.Key, y.Key);
} }
#endregion #endregion
@ -76,11 +83,11 @@ namespace NGenerics.Comparers {
#region IComparer<TKey> Members #region IComparer<TKey> Members
/// <inheritdoc /> /// <inheritdoc />
public int Compare(TKey x, TKey y) { public int Compare(TKey x, TKey y)
return comparer.Compare(x, y); {
return _comparer.Compare(x, y);
} }
#endregion #endregion
} }
} }

29
src/NGenerics/DataStructures/Comparers/ReverseComparer.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -14,16 +17,16 @@ using NGenerics.Util;
namespace NGenerics.Comparers namespace NGenerics.Comparers
{ {
/// <summary> /// <summary>
/// A comparer that wraps the IComparable interface to reproduce the opposite comparison result. /// A comparer that wraps the IComparable interface to reproduce the opposite comparison result.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the objects to compare.</typeparam> /// <typeparam name="T">The type of the objects to compare.</typeparam>
//[Serializable] //[Serializable]
public sealed class ReverseComparer<T> : IComparer<T> public sealed class ReverseComparer<T> : IComparer<T>
{ {
#region Globals #region Globals
private IComparer<T> comparerToUse; private IComparer<T> _comparerToUse;
#endregion #endregion
@ -31,27 +34,26 @@ namespace NGenerics.Comparers
/// <inheritdoc /> /// <inheritdoc />
public ReverseComparer() public ReverseComparer()
{ {
comparerToUse = Comparer<T>.Default; _comparerToUse = Comparer<T>.Default;
} }
/// <param name="comparer">The comparer to reverse.</param> /// <param name="comparer">The comparer to reverse.</param>
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception> /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
public ReverseComparer(IComparer<T> comparer) public ReverseComparer(IComparer<T> comparer)
{ {
Guard.ArgumentNotNull(comparer, "comparer"); Guard.ArgumentNotNull(comparer, "comparer");
comparerToUse = comparer; _comparerToUse = comparer;
} }
#endregion #endregion
#region IComparer<T> Members #region IComparer<T> Members
/// <inheritdoc /> /// <inheritdoc />
public int Compare(T x, T y) public int Compare(T x, T y)
{ {
return (comparerToUse.Compare(y, x)); return (_comparerToUse.Compare(y, x));
} }
#endregion #endregion
@ -67,14 +69,13 @@ namespace NGenerics.Comparers
{ {
get get
{ {
return comparerToUse; return _comparerToUse;
} }
set set
{ {
Guard.ArgumentNotNull(value, "value"); Guard.ArgumentNotNull(value, "value");
comparerToUse = value; _comparerToUse = value;
} }
} }

139
src/NGenerics/DataStructures/General/Heap.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -28,10 +31,10 @@ namespace NGenerics.DataStructures.General
{ {
#region Globals #region Globals
const string heapIsEmpty = "The heap is empty."; private const string heapIsEmpty = "The heap is empty.";
private readonly List<T> data; private readonly List<T> _data;
private readonly IComparer<T> comparerToUse; private readonly IComparer<T> _comparerToUse;
private readonly HeapType thisType; private readonly HeapType _thisType;
#endregion #endregion
@ -70,7 +73,7 @@ namespace NGenerics.DataStructures.General
/// <param name="type">The type of heap.</param> /// <param name="type">The type of heap.</param>
/// <param name="comparer">The comparer.</param> /// <param name="comparer">The comparer.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
public Heap(HeapType type, Comparison<T> comparer) : this(type, new ComparisonComparer<T>(comparer)){} public Heap(HeapType type, Comparison<T> comparer) : this(type, new ComparisonComparer<T>(comparer)) { }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Heap&lt;T&gt;"/> class. /// Initializes a new instance of the <see cref="Heap&lt;T&gt;"/> class.
@ -102,11 +105,11 @@ namespace NGenerics.DataStructures.General
throw new ArgumentOutOfRangeException("type"); throw new ArgumentOutOfRangeException("type");
} }
thisType = type; _thisType = type;
data = new List<T> {default(T)}; _data = new List<T> { default(T) };
comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer<T>(comparer); _comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer<T>(comparer);
} }
@ -124,11 +127,11 @@ namespace NGenerics.DataStructures.General
{ {
throw new ArgumentOutOfRangeException("type"); throw new ArgumentOutOfRangeException("type");
} }
thisType = type; _thisType = type;
data = new List<T>(capacity) {default(T)}; _data = new List<T>(capacity) { default(T) };
comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer<T>(comparer); _comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer<T>(comparer);
} }
#endregion #endregion
@ -136,7 +139,7 @@ namespace NGenerics.DataStructures.General
#region Public Members #region Public Members
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Root" lang="cs" title="The following example shows how to use the Root property."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Root" lang="cs" title="The following example shows how to use the Root property."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Root" lang="vbnet" title="The following example shows how to use the Root property."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Root" lang="vbnet" title="The following example shows how to use the Root property."/>
@ -154,12 +157,12 @@ namespace NGenerics.DataStructures.General
#endregion #endregion
return data[1]; return _data[1];
} }
} }
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="RemoveRoot" lang="cs" title="The following example shows how to use the RemoveRoot method."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="RemoveRoot" lang="cs" title="The following example shows how to use the RemoveRoot method."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="RemoveRoot" lang="vbnet" title="The following example shows how to use the RemoveRoot method."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="RemoveRoot" lang="vbnet" title="The following example shows how to use the RemoveRoot method."/>
@ -176,9 +179,9 @@ namespace NGenerics.DataStructures.General
#endregion #endregion
// The minimum item to return. // The minimum item to return.
var minimum = data[1]; var minimum = _data[1];
RemoveRootItem(minimum); RemoveRootItem(minimum);
return minimum; return minimum;
} }
@ -193,10 +196,9 @@ namespace NGenerics.DataStructures.General
/// </remarks> /// </remarks>
protected virtual void RemoveRootItem(T item) protected virtual void RemoveRootItem(T item)
{ {
// The last item in the heap // The last item in the heap
var last = data[Count]; var last = _data[Count];
data.RemoveAt(Count); _data.RemoveAt(Count);
// If there's still items left in this heap, re-heapify it. // If there's still items left in this heap, re-heapify it.
if (Count > 0) if (Count > 0)
@ -204,28 +206,27 @@ namespace NGenerics.DataStructures.General
// Re-heapify the binary tree to conform to the heap property // Re-heapify the binary tree to conform to the heap property
var counter = 1; var counter = 1;
while ((counter * 2) < (data.Count)) while ((counter * 2) < (_data.Count))
{ {
var child = counter * 2; var child = counter * 2;
if (((child + 1) < (data.Count)) && if (((child + 1) < (_data.Count)) &&
(comparerToUse.Compare(data[child + 1], data[child]) < 0)) (_comparerToUse.Compare(_data[child + 1], _data[child]) < 0))
{ {
child++; child++;
} }
if (comparerToUse.Compare(last, data[child]) <= 0) if (_comparerToUse.Compare(last, _data[child]) <= 0)
{ {
break; break;
} }
data[counter] = data[child]; _data[counter] = _data[child];
counter = child; counter = child;
} }
data[counter] = last; _data[counter] = last;
} }
} }
@ -242,7 +243,7 @@ namespace NGenerics.DataStructures.General
{ {
get get
{ {
return thisType; return _thisType;
} }
} }
@ -250,9 +251,9 @@ namespace NGenerics.DataStructures.General
#region ICollection<T> Members #region ICollection<T> Members
/// <inheritdoc />
/// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="IsEmpty" lang="cs" title="The following example shows how to use the IsEmpty property."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="IsEmpty" lang="cs" title="The following example shows how to use the IsEmpty property."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="IsEmpty" lang="vbnet" title="The following example shows how to use the IsEmpty property."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="IsEmpty" lang="vbnet" title="The following example shows how to use the IsEmpty property."/>
@ -265,19 +266,19 @@ namespace NGenerics.DataStructures.General
} }
} }
/// <inheritdoc />
/// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Contains" lang="cs" title="The following example shows how to use the Contains method."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Contains" lang="cs" title="The following example shows how to use the Contains method."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Contains" lang="vbnet" title="The following example shows how to use the Contains method."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Contains" lang="vbnet" title="The following example shows how to use the Contains method."/>
/// </example> /// </example>
public bool Contains(T item) public bool Contains(T item)
{ {
return data.Contains(item); return _data.Contains(item);
} }
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="CopyTo" lang="cs" title="The following example shows how to use the CopyTo method."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="CopyTo" lang="cs" title="The following example shows how to use the CopyTo method."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="CopyTo" lang="vbnet" title="The following example shows how to use the CopyTo method."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="CopyTo" lang="vbnet" title="The following example shows how to use the CopyTo method."/>
@ -295,13 +296,13 @@ namespace NGenerics.DataStructures.General
#endregion #endregion
for (var i = 1; i < data.Count; i++) for (var i = 1; i < _data.Count; i++)
{ {
array[arrayIndex++] = data[i]; array[arrayIndex++] = _data[i];
} }
} }
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Count" lang="cs" title="The following example shows how to use the Count property."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Count" lang="cs" title="The following example shows how to use the Count property."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Count" lang="vbnet" title="The following example shows how to use the Count property."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Count" lang="vbnet" title="The following example shows how to use the Count property."/>
@ -310,18 +311,18 @@ namespace NGenerics.DataStructures.General
{ {
get get
{ {
return data.Count - 1; return _data.Count - 1;
} }
} }
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Add" lang="cs" title="The following example shows how to use the Add method."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Add" lang="cs" title="The following example shows how to use the Add method."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Add" lang="vbnet" title="The following example shows how to use the Add method."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Add" lang="vbnet" title="The following example shows how to use the Add method."/>
/// </example> /// </example>
public void Add(T item) public void Add(T item)
{ {
AddItem(item); AddItem(item);
} }
/// <summary> /// <summary>
@ -333,24 +334,24 @@ namespace NGenerics.DataStructures.General
/// Derived classes can override this method to change the behavior of the <see cref="Add"/> method. /// Derived classes can override this method to change the behavior of the <see cref="Add"/> method.
/// </remarks> /// </remarks>
protected virtual void AddItem(T item) protected virtual void AddItem(T item)
{ {
// Add a dummy to the end of the list (it will be replaced) // Add a dummy to the end of the list (it will be replaced)
data.Add(default(T)); _data.Add(default(T));
var counter = data.Count - 1; var counter = _data.Count - 1;
while ((counter > 1) && (_comparerToUse.Compare(_data[counter / 2], item) > 0))
{
_data[counter] = _data[counter / 2];
counter = counter / 2;
}
while ((counter > 1) && (comparerToUse.Compare(data[counter / 2], item) > 0)) _data[counter] = item;
{ }
data[counter] = data[counter / 2];
counter = counter / 2;
}
data[counter] = item;
}
/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="NotSupportedException">Always.</exception> /// <exception cref="NotSupportedException">Always.</exception>
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] [SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
bool ICollection<T>.Remove(T item) bool ICollection<T>.Remove(T item)
@ -370,38 +371,38 @@ namespace NGenerics.DataStructures.General
/// </example> /// </example>
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for (var i = 1; i < data.Count; i++) for (var i = 1; i < _data.Count; i++)
{ {
yield return data[i]; yield return _data[i];
} }
} }
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Clear" lang="cs" title="The following example shows how to use the Clear method."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Clear" lang="cs" title="The following example shows how to use the Clear method."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Clear" lang="vbnet" title="The following example shows how to use the Clear method."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Clear" lang="vbnet" title="The following example shows how to use the Clear method."/>
/// </example> /// </example>
public void Clear() public void Clear()
{ {
ClearItems(); ClearItems();
}
/// <summary>
/// Clears all the objects in this instance.
/// </summary>
/// <remarks>
/// <b>Notes to Inheritors: </b>
/// Derived classes can override this method to change the behavior of the <see cref="Clear"/> method.
/// </remarks>
protected virtual void ClearItems()
{
_data.RemoveRange(1, _data.Count - 1); // Clears all objects in this instance except the first dummy one.
} }
/// <summary>
/// Clears all the objects in this instance.
/// </summary>
/// <remarks>
/// <b>Notes to Inheritors: </b>
/// Derived classes can override this method to change the behavior of the <see cref="Clear"/> method.
/// </remarks>
protected virtual void ClearItems()
{
data.RemoveRange(1, data.Count - 1); // Clears all objects in this instance except the first dummy one.
}
#endregion #endregion
#region ICollection<T> Members #region ICollection<T> Members
/// <inheritdoc /> /// <inheritdoc />
/// <example> /// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="IsReadOnly" lang="cs" title="The following example shows how to use the IsReadOnly property."/> /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="IsReadOnly" lang="cs" title="The following example shows how to use the IsReadOnly property."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="IsReadOnly" lang="vbnet" title="The following example shows how to use the IsReadOnly property."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="IsReadOnly" lang="vbnet" title="The following example shows how to use the IsReadOnly property."/>
@ -418,7 +419,7 @@ namespace NGenerics.DataStructures.General
#region IEnumerable Members #region IEnumerable Members
/// <inheritdoc /> /// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();

3
src/NGenerics/DataStructures/General/HeapType.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)

53
src/NGenerics/DataStructures/General/IHeap.cs

@ -1,4 +1,7 @@
/* // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -12,30 +15,30 @@ using System;
namespace NGenerics.DataStructures.General namespace NGenerics.DataStructures.General
{ {
/// <summary> /// <summary>
/// An interface for the <see cref="Heap{T}"/> data structure. /// An interface for the <see cref="Heap{T}"/> data structure.
/// </summary> /// </summary>
/// <typeparam name="T">The type of elements in the heap.</typeparam> /// <typeparam name="T">The type of elements in the heap.</typeparam>
public interface IHeap<T> public interface IHeap<T>
{ {
/// <summary> /// <summary>
/// Adds the specified item. /// Adds the specified item.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
void Add(T item); void Add(T item);
/// <summary> /// <summary>
/// Removes the root and returns it. /// Removes the root and returns it.
/// </summary> /// </summary>
/// <returns>The root of the <see cref="Heap{T}"/>.</returns> /// <returns>The root of the <see cref="Heap{T}"/>.</returns>
/// <exception cref="InvalidOperationException">The <see cref="Graph{T}"/> is empty.</exception> /// <exception cref="InvalidOperationException">The <see cref="Graph{T}"/> is empty.</exception>
T RemoveRoot(); T RemoveRoot();
/// <summary> /// <summary>
/// Gets the root. /// Gets the root.
/// </summary> /// </summary>
/// <value>The root.</value> /// <value>The root.</value>
/// <exception cref="InvalidOperationException">The <see cref="Heap{T}"/> is empty.</exception> /// <exception cref="InvalidOperationException">The <see cref="Heap{T}"/> is empty.</exception>
T Root { get; } T Root { get; }
} }
} }

41
src/NGenerics/DataStructures/Queues/IQueue.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -19,25 +22,25 @@ namespace NGenerics.DataStructures.Queues
/// <typeparam name="T">The type of the elements in the queue.</typeparam> /// <typeparam name="T">The type of the elements in the queue.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
public interface IQueue<T> public interface IQueue<T>
{ {
/// <summary> /// <summary>
/// Enqueues the item at the back of the queue. /// Enqueues the item at the back of the queue.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
void Enqueue(T item); void Enqueue(T item);
/// <summary> /// <summary>
/// Dequeues the item at the front of the queue. /// Dequeues the item at the front of the queue.
/// </summary> /// </summary>
/// <returns>The item at the front of the queue.</returns> /// <returns>The item at the front of the queue.</returns>
/// <exception cref="InvalidOperationException">The <see cref="Deque{T}"/> is empty.</exception> /// <exception cref="InvalidOperationException">The <see cref="Deque{T}"/> is empty.</exception>
T Dequeue(); T Dequeue();
/// <summary> /// <summary>
/// Peeks at the item in the front of the queue, without removing it. /// Peeks at the item in the front of the queue, without removing it.
/// </summary> /// </summary>
/// <returns>The item at the front of the queue.</returns> /// <returns>The item at the front of the queue.</returns>
/// <exception cref="InvalidOperationException">The <see cref="Deque{T}"/> is empty.</exception> /// <exception cref="InvalidOperationException">The <see cref="Deque{T}"/> is empty.</exception>
T Peek(); T Peek();
} }
} }

107
src/NGenerics/DataStructures/Queues/PriorityQueue.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -27,15 +30,15 @@ namespace NGenerics.DataStructures.Queues
/// <typeparam name="TPriority">The type of the priority in the <see cref="PriorityQueue{TPriority, TValue}"/>.</typeparam> /// <typeparam name="TPriority">The type of the priority in the <see cref="PriorityQueue{TPriority, TValue}"/>.</typeparam>
/// <typeparam name="TValue">The type of the elements in the <see cref="PriorityQueue{TPriority, TValue}"/>.</typeparam> /// <typeparam name="TValue">The type of the elements in the <see cref="PriorityQueue{TPriority, TValue}"/>.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
[SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
//[Serializable] //[Serializable]
public class PriorityQueue<TValue, TPriority> : ICollection<TValue>, IQueue<TValue> public class PriorityQueue<TValue, TPriority> : ICollection<TValue>, IQueue<TValue>
{ {
#region Globals #region Globals
private readonly RedBlackTreeList<TPriority, TValue> tree; private readonly RedBlackTreeList<TPriority, TValue> _tree;
private TPriority defaultPriority; private TPriority _defaultPriority;
private readonly PriorityQueueType queueType; private readonly PriorityQueueType _queueType;
#endregion #endregion
@ -47,17 +50,19 @@ namespace NGenerics.DataStructures.Queues
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Queues\PriorityQueueExamples.vb" region="Constructor" lang="vbnet" title="The following example shows how to use the default constructor."/> /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Queues\PriorityQueueExamples.vb" region="Constructor" lang="vbnet" title="The following example shows how to use the default constructor."/>
/// </example> /// </example>
public PriorityQueue(PriorityQueueType queueType) : public PriorityQueue(PriorityQueueType queueType) :
this(queueType, Comparer<TPriority>.Default) { this(queueType, Comparer<TPriority>.Default)
{
} }
/// <inheritdoc/> /// <inheritdoc/>
public PriorityQueue(PriorityQueueType queueType, IComparer<TPriority> comparer) { public PriorityQueue(PriorityQueueType queueType, IComparer<TPriority> comparer)
if ((queueType != PriorityQueueType.Minimum) && (queueType != PriorityQueueType.Maximum)) { {
if ((queueType != PriorityQueueType.Minimum) && (queueType != PriorityQueueType.Maximum))
{
throw new ArgumentOutOfRangeException("queueType"); throw new ArgumentOutOfRangeException("queueType");
} }
this.queueType = queueType; _queueType = queueType;
tree = new RedBlackTreeList<TPriority, TValue>(comparer); _tree = new RedBlackTreeList<TPriority, TValue>(comparer);
} }
/// <summary> /// <summary>
@ -67,8 +72,8 @@ namespace NGenerics.DataStructures.Queues
/// <param name="comparison">The comparison.</param> /// <param name="comparison">The comparison.</param>
/// <inheritdoc/> /// <inheritdoc/>
public PriorityQueue(PriorityQueueType queueType, Comparison<TPriority> comparison) : public PriorityQueue(PriorityQueueType queueType, Comparison<TPriority> comparison) :
this(queueType, new ComparisonComparer<TPriority>(comparison)) { this(queueType, new ComparisonComparer<TPriority>(comparison))
{
} }
#endregion #endregion
@ -187,7 +192,7 @@ namespace NGenerics.DataStructures.Queues
/// </example> /// </example>
public IEnumerator<TValue> GetEnumerator() public IEnumerator<TValue> GetEnumerator()
{ {
return tree.GetValueEnumerator(); return _tree.GetValueEnumerator();
} }
#endregion #endregion
@ -208,7 +213,7 @@ namespace NGenerics.DataStructures.Queues
/// </example> /// </example>
public bool Contains(TValue item) public bool Contains(TValue item)
{ {
return tree.ContainsValue(item); return _tree.ContainsValue(item);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -230,7 +235,7 @@ namespace NGenerics.DataStructures.Queues
#endregion #endregion
foreach (var association in tree) foreach (var association in _tree)
{ {
var items = association.Value; var items = association.Value;
@ -248,7 +253,7 @@ namespace NGenerics.DataStructures.Queues
/// </example> /// </example>
public void Add(TValue item) public void Add(TValue item)
{ {
Add(item, defaultPriority); Add(item, _defaultPriority);
} }
/// <summary> /// <summary>
@ -285,7 +290,7 @@ namespace NGenerics.DataStructures.Queues
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public IEnumerator<KeyValuePair<TPriority, TValue>> GetKeyEnumerator() public IEnumerator<KeyValuePair<TPriority, TValue>> GetKeyEnumerator()
{ {
return tree.GetKeyEnumerator(); return _tree.GetKeyEnumerator();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -334,7 +339,7 @@ namespace NGenerics.DataStructures.Queues
if (association.Value.Count == 0) if (association.Value.Count == 0)
{ {
tree.Remove(association.Key); _tree.Remove(association.Key);
} }
Count--; Count--;
@ -351,11 +356,11 @@ namespace NGenerics.DataStructures.Queues
{ {
get get
{ {
return defaultPriority; return _defaultPriority;
} }
set set
{ {
defaultPriority = value; _defaultPriority = value;
} }
} }
@ -369,7 +374,7 @@ namespace NGenerics.DataStructures.Queues
public bool Remove(TValue item, out TPriority priority) public bool Remove(TValue item, out TPriority priority)
{ {
return RemoveItem(item, out priority); return RemoveItem(item, out priority);
} }
/// <summary> /// <summary>
/// Removes the item. /// Removes the item.
/// </summary> /// </summary>
@ -383,7 +388,7 @@ namespace NGenerics.DataStructures.Queues
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#")] [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#")]
protected virtual bool RemoveItem(TValue item, out TPriority priority) protected virtual bool RemoveItem(TValue item, out TPriority priority)
{ {
var removed = tree.Remove(item, out priority); var removed = _tree.Remove(item, out priority);
if (removed) if (removed)
{ {
@ -392,7 +397,7 @@ namespace NGenerics.DataStructures.Queues
return removed; return removed;
} }
/// <summary> /// <summary>
/// Removes the items with the specified priority. /// Removes the items with the specified priority.
/// </summary> /// </summary>
@ -400,8 +405,8 @@ namespace NGenerics.DataStructures.Queues
/// <returns><c>true</c> if the priority exists in the <see cref="PriorityQueue{TValue, TPriority}"/> and has been removed; otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the priority exists in the <see cref="PriorityQueue{TValue, TPriority}"/> and has been removed; otherwise <c>false</c>.</returns>
public bool RemovePriorityGroup(TPriority priority) public bool RemovePriorityGroup(TPriority priority)
{ {
return RemoveItems(priority); return RemoveItems(priority);
} }
/// <summary> /// <summary>
/// Removes the items from the collection with the specified priority. /// Removes the items from the collection with the specified priority.
@ -409,30 +414,30 @@ namespace NGenerics.DataStructures.Queues
/// <param name="priority">The priority to search for.</param> /// <param name="priority">The priority to search for.</param>
/// <returns>An indication of whether items were found having the specified priority.</returns> /// <returns>An indication of whether items were found having the specified priority.</returns>
protected virtual bool RemoveItems(TPriority priority) protected virtual bool RemoveItems(TPriority priority)
{ {
LinkedList<TValue> items; LinkedList<TValue> items;
if (tree.TryGetValue(priority, out items)) if (_tree.TryGetValue(priority, out items))
{ {
tree.Remove(priority); _tree.Remove(priority);
Count -= items.Count; Count -= items.Count;
return true; return true;
} }
return false; return false;
} }
/// <summary> /// <summary>
/// Removes the items with the specified priority. /// Removes the items with the specified priority.
/// </summary> /// </summary>
/// <param name="priority">The priority.</param> /// <param name="priority">The priority.</param>
/// <returns>The items with the specified priority.</returns> /// <returns>The items with the specified priority.</returns>
public IList<TValue> GetPriorityGroup(TPriority priority) public IList<TValue> GetPriorityGroup(TPriority priority)
{ {
LinkedList<TValue> items; LinkedList<TValue> items;
return tree.TryGetValue(priority, out items) ? new List<TValue>(items) : new List<TValue>(); return _tree.TryGetValue(priority, out items) ? new List<TValue>(items) : new List<TValue>();
} }
/// <summary> /// <summary>
@ -465,7 +470,7 @@ namespace NGenerics.DataStructures.Queues
{ {
LinkedList<TValue> currentValues; LinkedList<TValue> currentValues;
if (tree.TryGetValue(priority, out currentValues)) if (_tree.TryGetValue(priority, out currentValues))
{ {
for (var i = 0; i < items.Count; i++) for (var i = 0; i < items.Count; i++)
{ {
@ -475,7 +480,7 @@ namespace NGenerics.DataStructures.Queues
else else
{ {
currentValues = new LinkedList<TValue>(items); currentValues = new LinkedList<TValue>(items);
tree.Add(priority, currentValues); _tree.Add(priority, currentValues);
} }
} }
@ -496,7 +501,7 @@ namespace NGenerics.DataStructures.Queues
{ {
LinkedList<TValue> list; LinkedList<TValue> list;
if (tree.TryGetValue(priority, out list)) if (_tree.TryGetValue(priority, out list))
{ {
list.AddLast(item); list.AddLast(item);
} }
@ -504,7 +509,7 @@ namespace NGenerics.DataStructures.Queues
{ {
list = new LinkedList<TValue>(); list = new LinkedList<TValue>();
list.AddLast(item); list.AddLast(item);
tree.Add(priority, list); _tree.Add(priority, list);
} }
Count++; Count++;
@ -519,7 +524,7 @@ namespace NGenerics.DataStructures.Queues
/// </remarks> /// </remarks>
protected virtual void ClearItems() protected virtual void ClearItems()
{ {
tree.Clear(); _tree.Clear();
Count = 0; Count = 0;
} }
@ -532,7 +537,7 @@ namespace NGenerics.DataStructures.Queues
/// </summary> /// </summary>
private void CheckTreeNotEmpty() private void CheckTreeNotEmpty()
{ {
if (tree.Count == 0) if (_tree.Count == 0)
{ {
throw new InvalidOperationException("The Priority Queue is empty."); throw new InvalidOperationException("The Priority Queue is empty.");
} }
@ -549,7 +554,7 @@ namespace NGenerics.DataStructures.Queues
#endregion #endregion
return queueType == PriorityQueueType.Maximum ? tree.Maximum : tree.Minimum; return _queueType == PriorityQueueType.Maximum ? _tree.Maximum : _tree.Minimum;
} }
#endregion #endregion

3
src/NGenerics/DataStructures/Queues/PriorityQueueType.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)

62
src/NGenerics/DataStructures/Trees/BinarySearchTreeBase.cs

@ -1,4 +1,7 @@
/* // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -18,7 +21,6 @@ using NGenerics.Util;
namespace NGenerics.DataStructures.Trees namespace NGenerics.DataStructures.Trees
{ {
/// <summary> /// <summary>
/// A base class for Binary Search Trees that store a single value in each node. /// A base class for Binary Search Trees that store a single value in each node.
/// </summary> /// </summary>
@ -26,12 +28,11 @@ namespace NGenerics.DataStructures.Trees
//[Serializable] //[Serializable]
public abstract class BinarySearchTreeBase<T> : ISearchTree<T> public abstract class BinarySearchTreeBase<T> : ISearchTree<T>
{ {
#region Globals #region Globals
internal const string alreadyContainedInTheTree = "The item is already contained in the tree."; internal const string alreadyContainedInTheTree = "The item is already contained in the tree.";
private BinaryTree<T> tree; private BinaryTree<T> _tree;
private readonly IComparer<T> comparer; private readonly IComparer<T> _comparer;
#endregion #endregion
@ -52,7 +53,7 @@ namespace NGenerics.DataStructures.Trees
/// </summary> /// </summary>
protected BinarySearchTreeBase() protected BinarySearchTreeBase()
{ {
comparer = Comparer<T>.Default; _comparer = Comparer<T>.Default;
} }
/// <summary> /// <summary>
@ -63,7 +64,7 @@ namespace NGenerics.DataStructures.Trees
protected BinarySearchTreeBase(IComparer<T> comparer) protected BinarySearchTreeBase(IComparer<T> comparer)
{ {
Guard.ArgumentNotNull(comparer, "comparer"); Guard.ArgumentNotNull(comparer, "comparer");
this.comparer = comparer; _comparer = comparer;
} }
/// <summary> /// <summary>
@ -73,7 +74,7 @@ namespace NGenerics.DataStructures.Trees
protected BinarySearchTreeBase(Comparison<T> comparison) protected BinarySearchTreeBase(Comparison<T> comparison)
{ {
Guard.ArgumentNotNull(comparison, "comparison"); Guard.ArgumentNotNull(comparison, "comparison");
comparer = new ComparisonComparer<T>(comparison); _comparer = new ComparisonComparer<T>(comparison);
} }
#endregion #endregion
@ -88,7 +89,7 @@ namespace NGenerics.DataStructures.Trees
{ {
get get
{ {
return comparer; return _comparer;
} }
} }
@ -106,16 +107,16 @@ namespace NGenerics.DataStructures.Trees
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
protected virtual BinaryTree<T> FindNode(T item) protected virtual BinaryTree<T> FindNode(T item)
{ {
if (tree == null) if (_tree == null)
{ {
return null; return null;
} }
var currentNode = tree; var currentNode = _tree;
while (currentNode != null) while (currentNode != null)
{ {
var nodeResult = comparer.Compare(item, currentNode.Data); var nodeResult = _comparer.Compare(item, currentNode.Data);
if (nodeResult == 0) if (nodeResult == 0)
{ {
@ -137,12 +138,12 @@ namespace NGenerics.DataStructures.Trees
/// <returns>The item if found, else null.</returns> /// <returns>The item if found, else null.</returns>
protected virtual BinaryTree<T> FindNode<TSearch>(TSearch value, CustomComparison<TSearch> customComparison) protected virtual BinaryTree<T> FindNode<TSearch>(TSearch value, CustomComparison<TSearch> customComparison)
{ {
if (tree == null) if (_tree == null)
{ {
return null; return null;
} }
var currentNode = tree; var currentNode = _tree;
while (currentNode != null) while (currentNode != null)
{ {
@ -182,11 +183,11 @@ namespace NGenerics.DataStructures.Trees
{ {
#region Debug #region Debug
Debug.Assert(tree != null); Debug.Assert(_tree != null);
#endregion #endregion
return FindMaximumNode(tree); return FindMaximumNode(_tree);
} }
@ -199,11 +200,11 @@ namespace NGenerics.DataStructures.Trees
{ {
#region Debug #region Debug
Debug.Assert(tree != null); Debug.Assert(_tree != null);
#endregion #endregion
return FindMinimumNode(tree); return FindMinimumNode(_tree);
} }
/// <summary> /// <summary>
@ -264,11 +265,11 @@ namespace NGenerics.DataStructures.Trees
{ {
get get
{ {
return tree; return _tree;
} }
set set
{ {
tree = value; _tree = value;
} }
} }
@ -343,18 +344,13 @@ namespace NGenerics.DataStructures.Trees
return FindMaximumNode().Data; return FindMaximumNode().Data;
} }
} } /// <inheritdoc/>
/// <inheritdoc/>
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public void DepthFirstTraversal(OrderedVisitor<T> visitor) public void DepthFirstTraversal(OrderedVisitor<T> visitor)
{ {
Guard.ArgumentNotNull(visitor, "visitor"); Guard.ArgumentNotNull(visitor, "visitor");
VisitNode(tree, visitor); VisitNode(_tree, visitor);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -362,12 +358,12 @@ namespace NGenerics.DataStructures.Trees
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public IEnumerator<T> GetOrderedEnumerator() public IEnumerator<T> GetOrderedEnumerator()
{ {
if (tree != null) if (_tree != null)
{ {
var trackingVisitor = new TrackingVisitor<T>(); var trackingVisitor = new TrackingVisitor<T>();
var inOrderVisitor = new InOrderVisitor<T>(trackingVisitor); var inOrderVisitor = new InOrderVisitor<T>(trackingVisitor);
tree.DepthFirstTraversal(inOrderVisitor); _tree.DepthFirstTraversal(inOrderVisitor);
var trackingList = trackingVisitor.TrackingList; var trackingList = trackingVisitor.TrackingList;
@ -423,7 +419,7 @@ namespace NGenerics.DataStructures.Trees
/// </remarks> /// </remarks>
protected virtual void ClearItems() protected virtual void ClearItems()
{ {
tree = null; _tree = null;
Count = 0; Count = 0;
} }
@ -457,11 +453,11 @@ namespace NGenerics.DataStructures.Trees
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
if (tree != null) if (_tree != null)
{ {
var stack = new Stack<BinaryTree<T>>(); var stack = new Stack<BinaryTree<T>>();
stack.Push(tree); stack.Push(_tree);
while (stack.Count > 0) while (stack.Count > 0)
{ {
@ -528,7 +524,7 @@ namespace NGenerics.DataStructures.Trees
#endregion #endregion
foreach (var association in tree) foreach (var association in _tree)
{ {
array[arrayIndex++] = association; array[arrayIndex++] = association;
} }

252
src/NGenerics/DataStructures/Trees/BinaryTree.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -27,72 +30,72 @@ namespace NGenerics.DataStructures.Trees
{ {
#region Globals #region Globals
private BinaryTree<T> leftSubtree; private BinaryTree<T> _leftSubtree;
private BinaryTree<T> rightSubtree; private BinaryTree<T> _rightSubtree;
private T data; private T _data;
#endregion #endregion
#region Construction #region Construction
/// <param name="data">The data contained in this node.</param> /// <param name="data">The data contained in this node.</param>
public BinaryTree(T data) : this(data, null, null) { } public BinaryTree(T data) : this(data, null, null) { }
/// <param name="data">The data.</param> /// <param name="data">The data.</param>
/// <param name="left">The data of the left subtree.</param> /// <param name="left">The data of the left subtree.</param>
/// <param name="right">The data of the right subtree.</param> /// <param name="right">The data of the right subtree.</param>
public BinaryTree(T data, T left, T right) : this(data, new BinaryTree<T>(left), new BinaryTree<T>(right)) { } public BinaryTree(T data, T left, T right) : this(data, new BinaryTree<T>(left), new BinaryTree<T>(right)) { }
/// <param name="data">The data contained in this node.</param> /// <param name="data">The data contained in this node.</param>
/// <param name="left">The left subtree.</param> /// <param name="left">The left subtree.</param>
/// <param name="right">The right subtree.</param> /// <param name="right">The right subtree.</param>
public BinaryTree(T data, BinaryTree<T> left, BinaryTree<T> right) public BinaryTree(T data, BinaryTree<T> left, BinaryTree<T> right)
: this(data, left, right, true) : this(data, left, right, true)
{ {
} }
/// <param name="data">The data contained in this node.</param> /// <param name="data">The data contained in this node.</param>
/// <param name="left">The left subtree.</param> /// <param name="left">The left subtree.</param>
/// <param name="right">The right subtree.</param> /// <param name="right">The right subtree.</param>
/// <param name="validateData"><see langword="true"/> to validate <paramref name="data"/>; otherwise <see langword="false"/>.</param> /// <param name="validateData"><see langword="true"/> to validate <paramref name="data"/>; otherwise <see langword="false"/>.</param>
internal BinaryTree(T data, BinaryTree<T> left, BinaryTree<T> right, bool validateData) internal BinaryTree(T data, BinaryTree<T> left, BinaryTree<T> right, bool validateData)
{ {
#region Validation #region Validation
//TODO: probably not the most efficient way of doing this but SplayTree needs to use a BinaryTree with null data. //TODO: probably not the most efficient way of doing this but SplayTree needs to use a BinaryTree with null data.
if (validateData) if (validateData)
{ {
Guard.ArgumentNotNull(data, "data"); Guard.ArgumentNotNull(data, "data");
} }
#endregion #endregion
leftSubtree = left; _leftSubtree = left;
if (left != null) if (left != null)
{ {
left.Parent = this; left.Parent = this;
} }
rightSubtree = right; _rightSubtree = right;
if (right != null) if (right != null)
{ {
right.Parent = this; right.Parent = this;
} }
this.data = data; _data = data;
} }
#endregion #endregion
#region ICollection<T> Members #region ICollection<T> Members
/// <inheritdoc /> /// <inheritdoc />
public bool IsEmpty public bool IsEmpty
{ {
get get
@ -101,16 +104,16 @@ namespace NGenerics.DataStructures.Trees
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public bool IsFull public bool IsFull
{ {
get get
{ {
return (leftSubtree != null) && (rightSubtree != null); return (_leftSubtree != null) && (_rightSubtree != null);
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Contains(T item) public bool Contains(T item)
{ {
foreach (var thisItem in this) foreach (var thisItem in this)
@ -124,7 +127,7 @@ namespace NGenerics.DataStructures.Trees
return false; return false;
} }
/// <inheritdoc /> /// <inheritdoc />
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
Guard.ArgumentNotNull(array, "array"); Guard.ArgumentNotNull(array, "array");
@ -144,19 +147,19 @@ namespace NGenerics.DataStructures.Trees
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public int Count public int Count
{ {
get get
{ {
var count = 0; var count = 0;
if (leftSubtree != null) if (_leftSubtree != null)
{ {
count++; count++;
} }
if (rightSubtree != null) if (_rightSubtree != null)
{ {
count++; count++;
} }
@ -165,27 +168,27 @@ namespace NGenerics.DataStructures.Trees
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public void Add(T item) public void Add(T item)
{ {
AddItem(new BinaryTree<T>(item)); AddItem(new BinaryTree<T>(item));
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Remove(T item) public bool Remove(T item)
{ {
if (leftSubtree != null) if (_leftSubtree != null)
{ {
if (leftSubtree.data.Equals(item)) if (_leftSubtree._data.Equals(item))
{ {
RemoveLeft(); RemoveLeft();
return true; return true;
} }
} }
if (rightSubtree != null) if (_rightSubtree != null)
{ {
if (rightSubtree.data.Equals(item)) if (_rightSubtree._data.Equals(item))
{ {
RemoveRight(); RemoveRight();
return true; return true;
@ -202,18 +205,18 @@ namespace NGenerics.DataStructures.Trees
/// <returns>A value indicating whether the child was found (and removed) from this tree.</returns> /// <returns>A value indicating whether the child was found (and removed) from this tree.</returns>
public bool Remove(BinaryTree<T> child) public bool Remove(BinaryTree<T> child)
{ {
if (leftSubtree != null) if (_leftSubtree != null)
{ {
if (leftSubtree == child) if (_leftSubtree == child)
{ {
RemoveLeft(); RemoveLeft();
return true; return true;
} }
} }
if (rightSubtree != null) if (_rightSubtree != null)
{ {
if (rightSubtree == child) if (_rightSubtree == child)
{ {
RemoveRight(); RemoveRight();
return true; return true;
@ -241,31 +244,31 @@ namespace NGenerics.DataStructures.Trees
yield return tree.Data; yield return tree.Data;
if (tree.leftSubtree != null) if (tree._leftSubtree != null)
{ {
stack.Push(tree.leftSubtree); stack.Push(tree._leftSubtree);
} }
if (tree.rightSubtree != null) if (tree._rightSubtree != null)
{ {
stack.Push(tree.rightSubtree); stack.Push(tree._rightSubtree);
} }
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual void Clear() public virtual void Clear()
{ {
if (leftSubtree != null) if (_leftSubtree != null)
{ {
leftSubtree.Parent = null; _leftSubtree.Parent = null;
leftSubtree = null; _leftSubtree = null;
} }
if (rightSubtree != null) if (_rightSubtree != null)
{ {
rightSubtree.Parent = null; _rightSubtree.Parent = null;
rightSubtree = null; _rightSubtree = null;
} }
} }
@ -273,31 +276,31 @@ namespace NGenerics.DataStructures.Trees
#region ITree<T> Members #region ITree<T> Members
/// <inheritdoc /> /// <inheritdoc />
void ITree<T>.Add(ITree<T> child) void ITree<T>.Add(ITree<T> child)
{ {
AddItem((BinaryTree<T>)child); AddItem((BinaryTree<T>)child);
} }
/// <inheritdoc /> /// <inheritdoc />
ITree<T> ITree<T>.GetChild(int index) ITree<T> ITree<T>.GetChild(int index)
{ {
return GetChild(index); return GetChild(index);
} }
/// <inheritdoc /> /// <inheritdoc />
bool ITree<T>.Remove(ITree<T> child) bool ITree<T>.Remove(ITree<T> child)
{ {
return Remove((BinaryTree<T>)child); return Remove((BinaryTree<T>)child);
} }
/// <inheritdoc /> /// <inheritdoc />
ITree<T> ITree<T>.FindNode(Predicate<T> condition) ITree<T> ITree<T>.FindNode(Predicate<T> condition)
{ {
return FindNode(condition); return FindNode(condition);
} }
/// <inheritdoc /> /// <inheritdoc />
ITree<T> ITree<T>.Parent ITree<T> ITree<T>.Parent
{ {
get get
@ -331,10 +334,10 @@ namespace NGenerics.DataStructures.Trees
{ {
return this; return this;
} }
if (leftSubtree != null) if (_leftSubtree != null)
{ {
var ret = leftSubtree.FindNode(condition); var ret = _leftSubtree.FindNode(condition);
if (ret != null) if (ret != null)
{ {
@ -342,9 +345,9 @@ namespace NGenerics.DataStructures.Trees
} }
} }
if (rightSubtree != null) if (_rightSubtree != null)
{ {
var ret = rightSubtree.FindNode(condition); var ret = _rightSubtree.FindNode(condition);
if (ret != null) if (ret != null)
{ {
@ -364,11 +367,11 @@ namespace NGenerics.DataStructures.Trees
{ {
get get
{ {
return leftSubtree; return _leftSubtree;
} }
set set
{ {
if (leftSubtree != null) if (_leftSubtree != null)
{ {
RemoveLeft(); RemoveLeft();
} }
@ -383,7 +386,7 @@ namespace NGenerics.DataStructures.Trees
value.Parent = this; value.Parent = this;
} }
leftSubtree = value; _leftSubtree = value;
} }
} }
@ -396,12 +399,11 @@ namespace NGenerics.DataStructures.Trees
{ {
get get
{ {
return rightSubtree; return _rightSubtree;
} }
set set
{ {
if (_rightSubtree != null)
if (rightSubtree != null)
{ {
RemoveRight(); RemoveRight();
} }
@ -416,16 +418,16 @@ namespace NGenerics.DataStructures.Trees
value.Parent = this; value.Parent = this;
} }
rightSubtree = value; _rightSubtree = value;
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual T Data public virtual T Data
{ {
get get
{ {
return data; return _data;
} }
set set
{ {
@ -435,11 +437,11 @@ namespace NGenerics.DataStructures.Trees
#endregion #endregion
data = value; _data = value;
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public int Degree public int Degree
{ {
get get
@ -459,14 +461,14 @@ namespace NGenerics.DataStructures.Trees
switch (index) switch (index)
{ {
case 0: case 0:
return leftSubtree; return _leftSubtree;
case 1: case 1:
return rightSubtree; return _rightSubtree;
default: default:
throw new ArgumentOutOfRangeException("index"); throw new ArgumentOutOfRangeException("index");
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual int Height public virtual int Height
{ {
get get
@ -475,7 +477,7 @@ namespace NGenerics.DataStructures.Trees
{ {
return 0; return 0;
} }
return 1 + FindMaximumChildHeight(); return 1 + FindMaximumChildHeight();
} }
} }
@ -494,21 +496,21 @@ namespace NGenerics.DataStructures.Trees
{ {
return; return;
} }
// Preorder visit // Preorder visit
orderedVisitor.VisitPreOrder(Data); orderedVisitor.VisitPreOrder(Data);
if (leftSubtree != null) if (_leftSubtree != null)
{ {
leftSubtree.DepthFirstTraversal(orderedVisitor); _leftSubtree.DepthFirstTraversal(orderedVisitor);
} }
// In-order visit // In-order visit
orderedVisitor.VisitInOrder(data); orderedVisitor.VisitInOrder(_data);
if (rightSubtree != null) if (_rightSubtree != null)
{ {
rightSubtree.DepthFirstTraversal(orderedVisitor); _rightSubtree.DepthFirstTraversal(orderedVisitor);
} }
// PostOrder visit // PostOrder visit
@ -551,7 +553,7 @@ namespace NGenerics.DataStructures.Trees
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual bool IsLeafNode public virtual bool IsLeafNode
{ {
get get
@ -565,10 +567,10 @@ namespace NGenerics.DataStructures.Trees
/// </summary> /// </summary>
public virtual void RemoveLeft() public virtual void RemoveLeft()
{ {
if (leftSubtree != null) if (_leftSubtree != null)
{ {
leftSubtree.Parent = null; _leftSubtree.Parent = null;
leftSubtree = null; _leftSubtree = null;
} }
} }
@ -577,10 +579,10 @@ namespace NGenerics.DataStructures.Trees
/// </summary> /// </summary>
public virtual void RemoveRight() public virtual void RemoveRight()
{ {
if (rightSubtree != null) if (_rightSubtree != null)
{ {
rightSubtree.Parent = null; _rightSubtree.Parent = null;
rightSubtree = null; _rightSubtree = null;
} }
} }
@ -595,8 +597,8 @@ namespace NGenerics.DataStructures.Trees
{ {
Guard.ArgumentNotNull(subtree, "subtree"); Guard.ArgumentNotNull(subtree, "subtree");
AddItem(subtree); AddItem(subtree);
} }
/// <summary> /// <summary>
/// Adds an item to the <see cref="ICollection{T}"/>. /// Adds an item to the <see cref="ICollection{T}"/>.
@ -608,24 +610,24 @@ namespace NGenerics.DataStructures.Trees
/// </remarks> /// </remarks>
protected virtual void AddItem(BinaryTree<T> subtree) protected virtual void AddItem(BinaryTree<T> subtree)
{ {
if (leftSubtree == null) if (_leftSubtree == null)
{ {
if (subtree.Parent != null) if (subtree.Parent != null)
{ {
subtree.Parent.Remove(subtree); subtree.Parent.Remove(subtree);
} }
leftSubtree = subtree; _leftSubtree = subtree;
subtree.Parent = this; subtree.Parent = this;
} }
else if (rightSubtree == null) else if (_rightSubtree == null)
{ {
if (subtree.Parent != null) if (subtree.Parent != null)
{ {
subtree.Parent.Remove(subtree); subtree.Parent.Remove(subtree);
} }
rightSubtree = subtree; _rightSubtree = subtree;
subtree.Parent = this; subtree.Parent = this;
} }
else else
@ -648,14 +650,14 @@ namespace NGenerics.DataStructures.Trees
var leftHeight = 0; var leftHeight = 0;
var rightHeight = 0; var rightHeight = 0;
if (leftSubtree != null) if (_leftSubtree != null)
{ {
leftHeight = leftSubtree.Height; leftHeight = _leftSubtree.Height;
} }
if (rightSubtree != null) if (_rightSubtree != null)
{ {
rightHeight = rightSubtree.Height; rightHeight = _rightSubtree.Height;
} }
return leftHeight > rightHeight ? leftHeight : rightHeight; return leftHeight > rightHeight ? leftHeight : rightHeight;
@ -680,7 +682,7 @@ namespace NGenerics.DataStructures.Trees
#region ICollection<T> Members #region ICollection<T> Members
/// <inheritdoc /> /// <inheritdoc />
public bool IsReadOnly public bool IsReadOnly
{ {
get get
@ -693,7 +695,7 @@ namespace NGenerics.DataStructures.Trees
#region IEnumerable Members #region IEnumerable Members
/// <inheritdoc /> /// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
@ -703,10 +705,10 @@ namespace NGenerics.DataStructures.Trees
#region Object Members #region Object Members
/// <inheritdoc /> /// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return data.ToString(); return _data.ToString();
} }
#endregion #endregion

9
src/NGenerics/DataStructures/Trees/ISearchTree.cs

@ -1,4 +1,7 @@
/* // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -15,13 +18,13 @@ using NGenerics.Patterns.Visitor;
namespace NGenerics.DataStructures.Trees namespace NGenerics.DataStructures.Trees
{ {
/// <summary> /// <summary>
/// An interface for Search Trees that mimic a dictionary. /// An interface for Search Trees that mimic a dictionary.
/// </summary> /// </summary>
/// <typeparam name="T">The type of element to hold in the tree.</typeparam> /// <typeparam name="T">The type of element to hold in the tree.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public interface ISearchTree<T> : ICollection<T> { public interface ISearchTree<T> : ICollection<T>
{
/// <summary> /// <summary>
/// Gets the largest item in the tree. /// Gets the largest item in the tree.
/// </summary> /// </summary>

13
src/NGenerics/DataStructures/Trees/ITree.cs

@ -1,4 +1,7 @@
/* // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -9,12 +12,14 @@
using System; using System;
namespace NGenerics.DataStructures.Trees { namespace NGenerics.DataStructures.Trees
{
/// <summary> /// <summary>
/// An interface for the tree data structure /// An interface for the tree data structure
/// </summary> /// </summary>
/// <typeparam name="T">The type of elements in the tree.</typeparam> /// <typeparam name="T">The type of elements in the tree.</typeparam>
public interface ITree<T> { public interface ITree<T>
{
/// <summary> /// <summary>
/// Adds the specified child to the tree. /// Adds the specified child to the tree.
/// </summary> /// </summary>
@ -72,6 +77,6 @@ namespace NGenerics.DataStructures.Trees {
/// Gets the parent of the current node. /// Gets the parent of the current node.
/// </summary> /// </summary>
/// <value>The parent of the current node.</value> /// <value>The parent of the current node.</value>
ITree<T> Parent { get;} ITree<T> Parent { get; }
} }
} }

3
src/NGenerics/DataStructures/Trees/NodeColor.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)

120
src/NGenerics/DataStructures/Trees/RedBlackTree.cs

@ -1,4 +1,7 @@
/* // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -17,32 +20,36 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace NGenerics.DataStructures.Trees { namespace NGenerics.DataStructures.Trees
{
/// <summary> /// <summary>
/// An implementation of a Red-Black tree. /// An implementation of a Red-Black tree.
/// </summary> /// </summary>
/// <typeparam name="T">The type of element to keep in the tree.</typeparam> /// <typeparam name="T">The type of element to keep in the tree.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
//[Serializable] //[Serializable]
public class RedBlackTree<T> : BinarySearchTreeBase<T> { public class RedBlackTree<T> : BinarySearchTreeBase<T>
{
#region Construction #region Construction
/// <inheritdoc /> /// <inheritdoc />
public RedBlackTree() { public RedBlackTree()
{
// Do nothing - the default Comparer will be used by the base class. // Do nothing - the default Comparer will be used by the base class.
} }
/// <inheritdoc/> /// <inheritdoc/>
public RedBlackTree(IComparer<T> comparer) public RedBlackTree(IComparer<T> comparer)
: base(comparer) { : base(comparer)
{
// Do nothing else. // Do nothing else.
} }
/// <inheritdoc/> /// <inheritdoc/>
public RedBlackTree(Comparison<T> comparison) public RedBlackTree(Comparison<T> comparison)
: base(comparison) { : base(comparison)
{
// Do nothing else. // Do nothing else.
} }
@ -54,10 +61,12 @@ namespace NGenerics.DataStructures.Trees {
/// Adds an element with the provided key and value to the <see cref="IDictionary{TKey,TValue}"/>. /// Adds an element with the provided key and value to the <see cref="IDictionary{TKey,TValue}"/>.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
protected override void AddItem(T item) { protected override void AddItem(T item)
{
#region Validation #region Validation
if (Equals(item, null)) { if (Equals(item, null))
{
throw new ArgumentNullException("item"); throw new ArgumentNullException("item");
} }
@ -78,8 +87,10 @@ namespace NGenerics.DataStructures.Trees {
/// <c>true</c> if the element is successfully removed; otherwise, <c>false</c>. This method also returns false if key was not found in the original <see cref="IDictionary{TKey,TValue}"/>. /// <c>true</c> if the element is successfully removed; otherwise, <c>false</c>. This method also returns false if key was not found in the original <see cref="IDictionary{TKey,TValue}"/>.
/// </returns> /// </returns>
/// <inheritdoc/> /// <inheritdoc/>
protected override bool RemoveItem(T item) { protected override bool RemoveItem(T item)
if (Tree != null) { {
if (Tree != null)
{
var startNode = new RedBlackTreeNode<T>(default(T)); var startNode = new RedBlackTreeNode<T>(default(T));
var childNode = startNode; var childNode = startNode;
@ -90,7 +101,8 @@ namespace NGenerics.DataStructures.Trees {
var direction = true; var direction = true;
while (childNode[direction] != null) { while (childNode[direction] != null)
{
var lastDirection = direction; var lastDirection = direction;
var grandParent = parent; var grandParent = parent;
@ -99,29 +111,41 @@ namespace NGenerics.DataStructures.Trees {
var comparisonValue = Comparer.Compare(childNode.Data, item); var comparisonValue = Comparer.Compare(childNode.Data, item);
if (comparisonValue == 0) { if (comparisonValue == 0)
{
foundNode = childNode; foundNode = childNode;
} }
direction = comparisonValue < 0; direction = comparisonValue < 0;
if ((IsBlack(childNode)) && (IsBlack(childNode[direction]))) { if ((IsBlack(childNode)) && (IsBlack(childNode[direction])))
if (IsRed(childNode[!direction])) { {
if (IsRed(childNode[!direction]))
{
parent = parent[lastDirection] = SingleRotation(childNode, direction); parent = parent[lastDirection] = SingleRotation(childNode, direction);
} else if (IsBlack(childNode[direction])) { }
else if (IsBlack(childNode[direction]))
{
var sibling = parent[!lastDirection]; var sibling = parent[!lastDirection];
if (sibling != null) { if (sibling != null)
if ((IsBlack(sibling.Left)) && (IsBlack(sibling.Right))) { {
if ((IsBlack(sibling.Left)) && (IsBlack(sibling.Right)))
{
parent.Color = NodeColor.Black; parent.Color = NodeColor.Black;
sibling.Color = NodeColor.Red; sibling.Color = NodeColor.Red;
childNode.Color = NodeColor.Red; childNode.Color = NodeColor.Red;
} else { }
else
{
var parentDirection = grandParent.Right == parent; var parentDirection = grandParent.Right == parent;
if (IsRed(sibling[lastDirection])) { if (IsRed(sibling[lastDirection]))
{
grandParent[parentDirection] = DoubleRotation(parent, lastDirection); grandParent[parentDirection] = DoubleRotation(parent, lastDirection);
} else if (IsRed(sibling[!lastDirection])) { }
else if (IsRed(sibling[!lastDirection]))
{
grandParent[parentDirection] = SingleRotation(parent, lastDirection); grandParent[parentDirection] = SingleRotation(parent, lastDirection);
} }
@ -134,18 +158,21 @@ namespace NGenerics.DataStructures.Trees {
} }
} }
if (foundNode != null) { if (foundNode != null)
{
foundNode.Data = childNode.Data; foundNode.Data = childNode.Data;
parent[parent.Right == childNode] = childNode[childNode.Left == null]; parent[parent.Right == childNode] = childNode[childNode.Left == null];
} }
Tree = startNode.Right; Tree = startNode.Right;
if (Tree != null) { if (Tree != null)
{
((RedBlackTreeNode<T>)Tree).Color = NodeColor.Black; ((RedBlackTreeNode<T>)Tree).Color = NodeColor.Black;
} }
if (foundNode != null) { if (foundNode != null)
{
return true; return true;
} }
} }
@ -164,7 +191,8 @@ namespace NGenerics.DataStructures.Trees {
/// <returns> /// <returns>
/// <c>true</c> if the specified node is red; otherwise, <c>false</c>. /// <c>true</c> if the specified node is red; otherwise, <c>false</c>.
/// </returns> /// </returns>
private static bool IsRed(RedBlackTreeNode<T> node) { private static bool IsRed(RedBlackTreeNode<T> node)
{
return (node != null) && (node.Color == NodeColor.Red); return (node != null) && (node.Color == NodeColor.Red);
} }
@ -175,7 +203,8 @@ namespace NGenerics.DataStructures.Trees {
/// <returns> /// <returns>
/// <c>true</c> if the specified node is black; otherwise, <c>false</c>. /// <c>true</c> if the specified node is black; otherwise, <c>false</c>.
/// </returns> /// </returns>
private static bool IsBlack(RedBlackTreeNode<T> node) { private static bool IsBlack(RedBlackTreeNode<T> node)
{
return (node == null) || (node.Color == NodeColor.Black); return (node == null) || (node.Color == NodeColor.Black);
} }
@ -185,28 +214,41 @@ namespace NGenerics.DataStructures.Trees {
/// <param name="node">The start node.</param> /// <param name="node">The start node.</param>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <returns>The node created in the insertion.</returns> /// <returns>The node created in the insertion.</returns>
private RedBlackTreeNode<T> InsertNode(RedBlackTreeNode<T> node, T item) { private RedBlackTreeNode<T> InsertNode(RedBlackTreeNode<T> node, T item)
if (node == null) { {
if (node == null)
{
node = new RedBlackTreeNode<T>(item); node = new RedBlackTreeNode<T>(item);
} else if (Comparer.Compare(item, node.Data) != 0) { }
else if (Comparer.Compare(item, node.Data) != 0)
{
var direction = Comparer.Compare(node.Data, item) < 0; var direction = Comparer.Compare(node.Data, item) < 0;
node[direction] = InsertNode(node[direction], item); node[direction] = InsertNode(node[direction], item);
if (IsRed(node[direction])) { if (IsRed(node[direction]))
if (IsRed(node[!direction])) { {
if (IsRed(node[!direction]))
{
node.Color = NodeColor.Red; node.Color = NodeColor.Red;
node.Left.Color = NodeColor.Black; node.Left.Color = NodeColor.Black;
node.Right.Color = NodeColor.Black; node.Right.Color = NodeColor.Black;
} else { }
if (IsRed(node[direction][direction])) { else
{
if (IsRed(node[direction][direction]))
{
node = SingleRotation(node, !direction); node = SingleRotation(node, !direction);
} else if (IsRed(node[direction][!direction])) { }
else if (IsRed(node[direction][!direction]))
{
node = DoubleRotation(node, !direction); node = DoubleRotation(node, !direction);
} }
} }
} }
} else { }
else
{
throw new ArgumentException(alreadyContainedInTheTree); throw new ArgumentException(alreadyContainedInTheTree);
} }
@ -219,7 +261,8 @@ namespace NGenerics.DataStructures.Trees {
/// <param name="node">The node on which to focus the rotation.</param> /// <param name="node">The node on which to focus the rotation.</param>
/// <param name="direction">The direction of the rotation. If direction is equal to true, a right rotation is performed. Other wise, a left rotation.</param> /// <param name="direction">The direction of the rotation. If direction is equal to true, a right rotation is performed. Other wise, a left rotation.</param>
/// <returns>The new root of the cluster.</returns> /// <returns>The new root of the cluster.</returns>
private static RedBlackTreeNode<T> SingleRotation(RedBlackTreeNode<T> node, bool direction) { private static RedBlackTreeNode<T> SingleRotation(RedBlackTreeNode<T> node, bool direction)
{
var childSibling = node[!direction]; var childSibling = node[!direction];
node[!direction] = childSibling[direction]; node[!direction] = childSibling[direction];
@ -237,7 +280,8 @@ namespace NGenerics.DataStructures.Trees {
/// <param name="node">The node on which to focus the rotation.</param> /// <param name="node">The node on which to focus the rotation.</param>
/// <param name="direction">The direction of the rotation. If direction is equal to true, a right rotation is performed. Other wise, a left rotation.</param> /// <param name="direction">The direction of the rotation. If direction is equal to true, a right rotation is performed. Other wise, a left rotation.</param>
/// <returns>The new root of the cluster.</returns> /// <returns>The new root of the cluster.</returns>
private static RedBlackTreeNode<T> DoubleRotation(RedBlackTreeNode<T> node, bool direction) { private static RedBlackTreeNode<T> DoubleRotation(RedBlackTreeNode<T> node, bool direction)
{
node[!direction] = SingleRotation(node[!direction], !direction); node[!direction] = SingleRotation(node[!direction], !direction);
return SingleRotation(node, direction); return SingleRotation(node, direction);
} }

436
src/NGenerics/DataStructures/Trees/RedBlackTreeDictionary.cs

@ -1,3 +1,6 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
/* /*
Copyright 2007-2013 The NGenerics Team Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team) (https://github.com/ngenerics/ngenerics/wiki/Team)
@ -22,222 +25,227 @@ using NGenerics.Patterns.Visitor;
namespace NGenerics.DataStructures.Trees namespace NGenerics.DataStructures.Trees
{ {
/// <summary> /// <summary>
/// An implementation of a Red-Black tree. /// An implementation of a Red-Black tree.
/// </summary> /// </summary>
/// <typeparam name="TKey">The type of the keys in the <see cref="RedBlackTree{TKey,TValue}"/>.</typeparam> /// <typeparam name="TKey">The type of the keys in the <see cref="RedBlackTree{TKey,TValue}"/>.</typeparam>
/// <typeparam name="TValue">The type of the values in the <see cref="RedBlackTree{TKey,TValue}"/>.</typeparam> /// <typeparam name="TValue">The type of the values in the <see cref="RedBlackTree{TKey,TValue}"/>.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
#if (!SILVERLIGHT && !WINDOWSPHONE) #if (!SILVERLIGHT && !WINDOWSPHONE)
//[Serializable] //[Serializable]
#endif #endif
public class RedBlackTree<TKey, TValue> : RedBlackTree<KeyValuePair<TKey, TValue>>, IDictionary<TKey, TValue> // BinarySearchTreeBase<TKey, TValue> public class RedBlackTree<TKey, TValue> : RedBlackTree<KeyValuePair<TKey, TValue>>, IDictionary<TKey, TValue> // BinarySearchTreeBase<TKey, TValue>
{ {
#region Construction #region Construction
/// <inheritdoc /> /// <inheritdoc />
public RedBlackTree() : base(new KeyValuePairComparer<TKey, TValue>()) public RedBlackTree() : base(new KeyValuePairComparer<TKey, TValue>())
{ {
// Do nothing - the default Comparer will be used by the base class. // Do nothing - the default Comparer will be used by the base class.
} }
/// <inheritdoc/> /// <inheritdoc/>
public RedBlackTree(IComparer<TKey> comparer) public RedBlackTree(IComparer<TKey> comparer)
: base(new KeyValuePairComparer<TKey, TValue>(comparer)) : base(new KeyValuePairComparer<TKey, TValue>(comparer))
{ {
// Do nothing else. // Do nothing else.
} }
/// <inheritdoc/> /// <inheritdoc/>
public RedBlackTree(Comparison<TKey> comparison) public RedBlackTree(Comparison<TKey> comparison)
: base(new KeyValuePairComparer<TKey, TValue>(comparison)) : base(new KeyValuePairComparer<TKey, TValue>(comparison))
{ {
// Do nothing else. // Do nothing else.
} }
#endregion #endregion
#region Private Members #region Private Members
private RedBlackTreeNode<KeyValuePair<TKey, TValue>> FindNode(TKey key) private RedBlackTreeNode<KeyValuePair<TKey, TValue>> FindNode(TKey key)
{ {
return base.FindNode(new KeyValuePair<TKey, TValue>(key, default(TValue))) as RedBlackTreeNode<KeyValuePair<TKey, TValue>>; return base.FindNode(new KeyValuePair<TKey, TValue>(key, default(TValue))) as RedBlackTreeNode<KeyValuePair<TKey, TValue>>;
} }
private bool Contains(KeyValuePair<TKey, TValue> item, bool checkValue) { private bool Contains(KeyValuePair<TKey, TValue> item, bool checkValue)
var node = FindNode(item); {
var node = FindNode(item);
if ((node != null) && !checkValue) {
return true; if ((node != null) && !checkValue)
} {
return true;
return node != null && Equals(item.Value, node.Data.Value); }
}
return node != null && Equals(item.Value, node.Data.Value);
#endregion }
#region IDictionary<TKey,TValue> Members #endregion
/// <summary> #region IDictionary<TKey,TValue> Members
/// Removes the element with the specified key from the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// </summary> /// <summary>
/// <param name="key">The key of the element to remove.</param> /// Removes the element with the specified key from the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// <returns> /// </summary>
/// true if the element is successfully removed; otherwise, false. This method also returns false if <paramref name="key"/> was not found in the original <see cref="T:System.Collections.Generic.IDictionary`2"/>. /// <param name="key">The key of the element to remove.</param>
/// </returns> /// <returns>
/// <exception cref="T:System.ArgumentNullException"> /// true if the element is successfully removed; otherwise, false. This method also returns false if <paramref name="key"/> was not found in the original <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// <paramref name="key"/> is null. /// </returns>
/// </exception> /// <exception cref="T:System.ArgumentNullException">
/// <exception cref="T:System.NotSupportedException"> /// <paramref name="key"/> is null.
/// The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only. /// </exception>
/// </exception> /// <exception cref="T:System.NotSupportedException">
public bool Remove(TKey key) { /// The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.
return Remove(new KeyValuePair<TKey, TValue>(key, default(TValue))); /// </exception>
} public bool Remove(TKey key)
{
/// <summary> return Remove(new KeyValuePair<TKey, TValue>(key, default(TValue)));
/// Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2"/>. }
/// </summary>
/// <param name="key">The object to use as the key of the element to add.</param> /// <summary>
/// <param name="value">The object to use as the value of the element to add.</param> /// Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// <exception cref="T:System.ArgumentNullException"> /// </summary>
/// <paramref name="key"/> is null. /// <param name="key">The object to use as the key of the element to add.</param>
/// </exception> /// <param name="value">The object to use as the value of the element to add.</param>
/// <exception cref="T:System.ArgumentException"> /// <exception cref="T:System.ArgumentNullException">
/// An element with the same key already exists in the <see cref="T:System.Collections.Generic.IDictionary`2"/>. /// <paramref name="key"/> is null.
/// </exception> /// </exception>
/// <exception cref="T:System.NotSupportedException"> /// <exception cref="T:System.ArgumentException">
/// The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only. /// An element with the same key already exists in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// </exception> /// </exception>
public void Add(TKey key, TValue value) { /// <exception cref="T:System.NotSupportedException">
/// The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.
if (Equals(key, null)) /// </exception>
{ public void Add(TKey key, TValue value)
throw new ArgumentNullException("key"); {
} if (Equals(key, null))
{
Add(new KeyValuePair<TKey,TValue>(key, value)); throw new ArgumentNullException("key");
} }
/// <summary> Add(new KeyValuePair<TKey, TValue>(key, value));
/// Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the specified key. }
/// </summary>
/// <param name="key">The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.</param> /// <summary>
/// <returns> /// Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the specified key.
/// true if the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the key; otherwise, false. /// </summary>
/// </returns> /// <param name="key">The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.</param>
/// <exception cref="T:System.ArgumentNullException"> /// <returns>
/// <paramref name="key"/> is null. /// true if the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the key; otherwise, false.
/// </exception> /// </returns>
public bool ContainsKey(TKey key) { /// <exception cref="T:System.ArgumentNullException">
return Contains(new KeyValuePair<TKey, TValue>(key, default(TValue)), false); /// <paramref name="key"/> is null.
} /// </exception>
public bool ContainsKey(TKey key)
/// <summary> {
/// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the <see cref="T:System.Collections.Generic.IDictionary`2"/>. return Contains(new KeyValuePair<TKey, TValue>(key, default(TValue)), false);
/// </summary> }
/// <value></value>
/// <example> /// <summary>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="Keys" lang="cs" title="The following example shows how to use the Keys property."/> /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="Keys" lang="vbnet" title="The following example shows how to use the Keys property."/> /// </summary>
/// </example> /// <value></value>
public ICollection<TKey> Keys /// <example>
{ /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="Keys" lang="cs" title="The following example shows how to use the Keys property."/>
get /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="Keys" lang="vbnet" title="The following example shows how to use the Keys property."/>
{ /// </example>
// Get the keys in sorted order public ICollection<TKey> Keys
var visitor = new KeyTrackingVisitor<TKey, TValue>(); {
var inOrderVisitor = new InOrderVisitor<KeyValuePair<TKey, TValue>>(visitor); get
DepthFirstTraversal(inOrderVisitor); {
return new ReadOnlyCollection<TKey>(visitor.TrackingList); // Get the keys in sorted order
} var visitor = new KeyTrackingVisitor<TKey, TValue>();
} var inOrderVisitor = new InOrderVisitor<KeyValuePair<TKey, TValue>>(visitor);
DepthFirstTraversal(inOrderVisitor);
return new ReadOnlyCollection<TKey>(visitor.TrackingList);
/// <inheritdoc /> }
/// <example> }
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="TryGetValue" lang="cs" title="The following example shows how to use the TryGetValue method."/>
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="TryGetValue" lang="vbnet" title="The following example shows how to use the TryGetValue method."/>
/// </example> /// <inheritdoc />
public bool TryGetValue(TKey key, out TValue value) /// <example>
{ /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="TryGetValue" lang="cs" title="The following example shows how to use the TryGetValue method."/>
var node = FindNode(new KeyValuePair<TKey, TValue>(key, default(TValue))); /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="TryGetValue" lang="vbnet" title="The following example shows how to use the TryGetValue method."/>
/// </example>
if (node == null) public bool TryGetValue(TKey key, out TValue value)
{ {
value = default(TValue); var node = FindNode(new KeyValuePair<TKey, TValue>(key, default(TValue)));
return false;
} if (node == null)
{
value = node.Data.Value; value = default(TValue);
return true; return false;
} }
/// <summary> value = node.Data.Value;
/// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the <see cref="T:System.Collections.Generic.IDictionary`2"/>. return true;
/// </summary> }
/// <value></value>
/// <example> /// <summary>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="Values" lang="cs" title="The following example shows how to use the Values property."/> /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="Values" lang="vbnet" title="The following example shows how to use the Values property."/> /// </summary>
/// </example> /// <value></value>
public ICollection<TValue> Values /// <example>
{ /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="Values" lang="cs" title="The following example shows how to use the Values property."/>
get /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="Values" lang="vbnet" title="The following example shows how to use the Values property."/>
{ /// </example>
var visitor = new ValueTrackingVisitor<TKey, TValue>(); public ICollection<TValue> Values
var inOrderVisitor = new InOrderVisitor<KeyValuePair<TKey, TValue>>(visitor); {
get
DepthFirstTraversal(inOrderVisitor); {
var visitor = new ValueTrackingVisitor<TKey, TValue>();
return new ReadOnlyCollection<TValue>(visitor.TrackingList); var inOrderVisitor = new InOrderVisitor<KeyValuePair<TKey, TValue>>(visitor);
}
} DepthFirstTraversal(inOrderVisitor);
return new ReadOnlyCollection<TValue>(visitor.TrackingList);
/// <summary> }
/// Gets or sets the value with the specified key. }
/// </summary>
/// <value>The key of the item to set or get.</value>
public TValue this[TKey key] /// <summary>
{ /// Gets or sets the value with the specified key.
get /// </summary>
{ /// <value>The key of the item to set or get.</value>
var node = FindNode(key); public TValue this[TKey key]
{
if (node == null) get
{ {
throw new KeyNotFoundException("key"); var node = FindNode(key);
}
if (node == null)
return node.Data.Value; {
} throw new KeyNotFoundException("key");
set }
{
var node = FindNode(key); return node.Data.Value;
}
if (node == null) set
{ {
throw new KeyNotFoundException("key"); var node = FindNode(key);
}
if (node == null)
node.Data = new KeyValuePair<TKey,TValue>(key, value); {
} throw new KeyNotFoundException("key");
} }
#endregion node.Data = new KeyValuePair<TKey, TValue>(key, value);
}
#region ICollection<KeyValuePair<TKey,TValue>> Members }
/// <inheritdoc /> #endregion
/// <example>
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="Contains" lang="cs" title="The following example shows how to use the Contains method."/> #region ICollection<KeyValuePair<TKey,TValue>> Members
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="Contains" lang="vbnet" title="The following example shows how to use the Contains method."/>
/// </example> /// <inheritdoc />
public override bool Contains(KeyValuePair<TKey, TValue> item) { /// <example>
return Contains(item, true); /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\Trees\BinarySearchTreeBaseExamples.cs" region="Contains" lang="cs" title="The following example shows how to use the Contains method."/>
} /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\Trees\BinarySearchTreeBaseExamples.vb" region="Contains" lang="vbnet" title="The following example shows how to use the Contains method."/>
/// </example>
#endregion public override bool Contains(KeyValuePair<TKey, TValue> item)
} {
return Contains(item, true);
}
#endregion
}
} }

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save