diff --git a/sources/core/Stride.Core.Design/Extensions/ObjectExtensions.cs b/sources/core/Stride.Core.Design/Extensions/ObjectExtensions.cs
index 1585c6f214..1c731e5676 100644
--- a/sources/core/Stride.Core.Design/Extensions/ObjectExtensions.cs
+++ b/sources/core/Stride.Core.Design/Extensions/ObjectExtensions.cs
@@ -3,7 +3,6 @@
using System.Collections;
using System.Runtime.CompilerServices;
-using Stride.Core.Annotations;
namespace Stride.Core.Extensions;
@@ -17,8 +16,7 @@ public static class ObjectExtensions
///
/// The object.
/// The return value of , or "(null)" if is null, or (ExceptionInToString)" if thrown an exception.
- [NotNull]
- public static string ToStringSafe([CanBeNull] this object obj)
+ public static string ToStringSafe(this object? obj)
{
try
{
@@ -54,8 +52,16 @@ public static string ToStringSafe([CanBeNull] this object obj)
if (obj is IEnumerable enumerableT)
return enumerableT;
- var enumerable = obj as IEnumerable;
- return enumerable?.Cast() ?? Yield((T?)obj);
+ if (obj is IEnumerable enumerable)
+ return enumerable.OfType();
+
+ if (obj is null)
+ return Yield((T?)obj);
+
+ if (obj is T t)
+ return Yield(t);
+
+ return [];
}
///
@@ -67,7 +73,6 @@ public static string ToStringSafe([CanBeNull] this object obj)
/// The name of the argument, in case an must be thrown.
/// The given object.
/// This method can be used to test for null argument when forwarding members of the object to the base or this constructor.
- [NotNull]
public static T SafeArgument(this T obj, [CallerArgumentExpression(nameof(obj))] string argumentName = "") where T : class
{
#if NET6_0_OR_GREATER
diff --git a/sources/core/Stride.Core.Reflection/ITypeDescriptorFactory.cs b/sources/core/Stride.Core.Reflection/ITypeDescriptorFactory.cs
index dc8a5bf257..2b6a5343e4 100644
--- a/sources/core/Stride.Core.Reflection/ITypeDescriptorFactory.cs
+++ b/sources/core/Stride.Core.Reflection/ITypeDescriptorFactory.cs
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
+
namespace Stride.Core.Reflection;
///
@@ -19,5 +21,6 @@ public interface ITypeDescriptorFactory
///
/// The type.
/// ITypeDescriptor.
+ [return: NotNullIfNotNull(nameof(type))]
ITypeDescriptor? Find(Type? type);
}
diff --git a/sources/core/Stride.Core.Reflection/MemberDescriptors/IMemberDescriptor.cs b/sources/core/Stride.Core.Reflection/MemberDescriptors/IMemberDescriptor.cs
index 148bd867a4..a2da4c4d70 100644
--- a/sources/core/Stride.Core.Reflection/MemberDescriptors/IMemberDescriptor.cs
+++ b/sources/core/Stride.Core.Reflection/MemberDescriptors/IMemberDescriptor.cs
@@ -124,5 +124,5 @@ public interface IMemberDescriptor
///
/// The this object.
/// The value.
- void Set(object thisObject, object value);
+ void Set(object thisObject, object? value);
}
diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptorFactory.cs b/sources/core/Stride.Core.Reflection/TypeDescriptorFactory.cs
index 6630ba772b..526f0e5723 100644
--- a/sources/core/Stride.Core.Reflection/TypeDescriptorFactory.cs
+++ b/sources/core/Stride.Core.Reflection/TypeDescriptorFactory.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
using Stride.Core.Yaml.Serialization;
namespace Stride.Core.Reflection;
@@ -45,6 +46,7 @@ public TypeDescriptorFactory(IAttributeRegistry attributeRegistry, bool emitDefa
public IAttributeRegistry AttributeRegistry { get; }
+ [return: NotNullIfNotNull(nameof(type))]
public ITypeDescriptor? Find(Type? type)
{
if (type is null)
diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs
index 03ecb29384..b5739fbbf3 100644
--- a/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs
+++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs
@@ -153,5 +153,5 @@ public static bool IsCollection(Type type)
///
/// The collection.
/// The number of elements of a collection, -1 if it cannot determine the number of elements.
- public abstract int GetCollectionCount(object collection);
+ public abstract int GetCollectionCount(object? collection);
}
diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ListDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ListDescriptor.cs
index 241980fe39..8fe82c082d 100644
--- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ListDescriptor.cs
+++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ListDescriptor.cs
@@ -193,7 +193,7 @@ public override void RemoveAt(object list, int index)
///
/// The list.
/// The number of elements of a list, -1 if it cannot determine the number of elements.
- public override int GetCollectionCount(object list)
+ public override int GetCollectionCount(object? list)
{
return list == null || getListCountMethod == null ? -1 : getListCountMethod(list);
}
diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs
index de41799d11..84698b6714 100644
--- a/sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs
+++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs
@@ -236,7 +236,7 @@ public override bool IsReadOnly(object collection)
///
/// The collection.
/// The number of elements of a collection, -1 if it cannot determine the number of elements.
- public override int GetCollectionCount(object collection)
+ public override int GetCollectionCount(object? collection)
{
return collection == null || getCollectionCountMethod == null ? -1 : getCollectionCountMethod(collection);
}
diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/SetDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/SetDescriptor.cs
index 1abb44da0d..865602a556 100644
--- a/sources/core/Stride.Core.Reflection/TypeDescriptors/SetDescriptor.cs
+++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/SetDescriptor.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Stride.Core.Yaml.Serialization;
@@ -132,7 +133,7 @@ public bool Contains(object set, object? value)
///
/// The set.
/// The number of elements of a set, -1 if it cannot determine the number of elements.
- public override int GetCollectionCount(object set)
+ public override int GetCollectionCount([NotNull] object? set)
{
ArgumentNullException.ThrowIfNull(set);
return countMethod.Invoke(set);
diff --git a/sources/editor/Stride.Core.Assets.Editor/Quantum/NodePresenters/AssetVirtualNodePresenter.cs b/sources/editor/Stride.Core.Assets.Editor/Quantum/NodePresenters/AssetVirtualNodePresenter.cs
index 4e30587984..1c792fe7fa 100644
--- a/sources/editor/Stride.Core.Assets.Editor/Quantum/NodePresenters/AssetVirtualNodePresenter.cs
+++ b/sources/editor/Stride.Core.Assets.Editor/Quantum/NodePresenters/AssetVirtualNodePresenter.cs
@@ -25,13 +25,16 @@ public AssetVirtualNodePresenter([NotNull] INodePresenterFactoryInternal factory
this.isOverridden = isOverridden;
}
- public override void Dispose()
+ protected override void Dispose(bool disposing)
{
- base.Dispose();
- if (AssociatedNode.Node != null)
+ base.Dispose(disposing);
+ if (disposing)
{
- ((IAssetNode)AssociatedNode.Node).OverrideChanging -= OnOverrideChanging;
- ((IAssetNode)AssociatedNode.Node).OverrideChanged -= OnOverrideChanged;
+ if (AssociatedNode.Node != null)
+ {
+ ((IAssetNode)AssociatedNode.Node).OverrideChanging -= OnOverrideChanging;
+ ((IAssetNode)AssociatedNode.Node).OverrideChanged -= OnOverrideChanged;
+ }
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestContainerContext.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestContainerContext.cs
index be98a2c1b7..e07c9666ec 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestContainerContext.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestContainerContext.cs
@@ -1,34 +1,33 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System.Windows.Threading;
-using Stride.Core.Presentation.View;
+
+using Stride.Core.Presentation.Services;
using Stride.Core.Presentation.ViewModels;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum.Tests.Helpers
+namespace Stride.Core.Presentation.Quantum.Tests.Helpers;
+
+public class TestContainerContext
{
- public class TestContainerContext
+ public TestContainerContext()
{
- public TestContainerContext()
- {
- NodeContainer = new NodeContainer();
- GraphViewModelService = new GraphViewModelService(NodeContainer);
- ServiceProvider = new ViewModelServiceProvider();
- ServiceProvider.RegisterService(new DispatcherService(Dispatcher.CurrentDispatcher));
- ServiceProvider.RegisterService(GraphViewModelService);
- }
+ NodeContainer = new NodeContainer();
+ GraphViewModelService = new GraphViewModelService(NodeContainer);
+ ServiceProvider = new ViewModelServiceProvider();
+ ServiceProvider.RegisterService(new NullDispatcherService());
+ ServiceProvider.RegisterService(GraphViewModelService);
+ }
- public ViewModelServiceProvider ServiceProvider { get; }
+ public ViewModelServiceProvider ServiceProvider { get; }
- public GraphViewModelService GraphViewModelService { get; }
+ public GraphViewModelService GraphViewModelService { get; }
- public NodeContainer NodeContainer { get; }
+ public NodeContainer NodeContainer { get; }
- public TestInstanceContext CreateInstanceContext(object instance)
- {
- var rootNode = NodeContainer.GetOrCreateNode(instance);
- var context = new TestInstanceContext(this, rootNode);
- return context;
- }
+ public TestInstanceContext CreateInstanceContext(object instance)
+ {
+ var rootNode = NodeContainer.GetOrCreateNode(instance);
+ var context = new TestInstanceContext(this, rootNode);
+ return context;
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestInstanceContext.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestInstanceContext.cs
index 153fc2d42a..d6711f8f7f 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestInstanceContext.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/TestInstanceContext.cs
@@ -1,31 +1,31 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
+
using Stride.Core.Presentation.Quantum.Presenters;
using Stride.Core.Presentation.Quantum.ViewModels;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum.Tests.Helpers
+namespace Stride.Core.Presentation.Quantum.Tests.Helpers;
+
+public class TestInstanceContext
{
- public class TestInstanceContext
- {
- private readonly TestContainerContext context;
+ private readonly TestContainerContext context;
- public TestInstanceContext(TestContainerContext context, IObjectNode rootNode)
- {
- this.context = context;
- RootNode = rootNode;
- PropertyProvider = new Types.TestPropertyProvider(rootNode);
- }
+ public TestInstanceContext(TestContainerContext context, IObjectNode rootNode)
+ {
+ this.context = context;
+ RootNode = rootNode;
+ PropertyProvider = new Types.TestPropertyProvider(rootNode);
+ }
- public IPropertyProviderViewModel PropertyProvider { get; }
+ public IPropertyProviderViewModel PropertyProvider { get; }
- public IObjectNode RootNode { get; }
+ public IObjectNode RootNode { get; }
- public INodePresenterFactory Factory => context.GraphViewModelService.NodePresenterFactory;
+ public INodePresenterFactory Factory => context.GraphViewModelService.NodePresenterFactory;
- public GraphViewModel CreateViewModel()
- {
- return GraphViewModel.Create(context.ServiceProvider, new[] { PropertyProvider });
- }
+ public GraphViewModel CreateViewModel()
+ {
+ return GraphViewModel.Create(context.ServiceProvider, [PropertyProvider])!;
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/Types.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/Types.cs
index dfbca6810b..293af19d8e 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/Types.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Helpers/Types.cs
@@ -1,76 +1,72 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System.Collections.Generic;
-using Stride.Core;
-using Stride.Core.Presentation.Quantum.Presenters;
+
using Stride.Core.Quantum;
-using Stride.Core.Quantum.References;
-namespace Stride.Core.Presentation.Quantum.Tests.Helpers
+namespace Stride.Core.Presentation.Quantum.Tests.Helpers;
+
+public static class Types
{
- public static class Types
+ public class TestPropertyProvider : IPropertyProviderViewModel
{
- public class TestPropertyProvider : IPropertyProviderViewModel
- {
- private readonly IObjectNode rootNode;
+ private readonly IObjectNode rootNode;
- public TestPropertyProvider(IObjectNode rootNode)
- {
- this.rootNode = rootNode;
- }
- public bool CanProvidePropertiesViewModel => true;
+ public TestPropertyProvider(IObjectNode rootNode)
+ {
+ this.rootNode = rootNode;
+ }
+ public bool CanProvidePropertiesViewModel => true;
- public IObjectNode GetRootNode()
- {
- return rootNode;
- }
+ public IObjectNode GetRootNode()
+ {
+ return rootNode;
+ }
- bool IPropertyProviderViewModel.ShouldConstructMember(IMemberNode member) => true;
+ bool IPropertyProviderViewModel.ShouldConstructMember(IMemberNode member) => true;
- bool IPropertyProviderViewModel.ShouldConstructItem(IObjectNode collection, NodeIndex index) => true;
- }
+ bool IPropertyProviderViewModel.ShouldConstructItem(IObjectNode collection, NodeIndex index) => true;
+ }
- public class SimpleObject
- {
- public string Name { get; set; }
+ public class SimpleObject
+ {
+ public required string Name { get; set; }
- public string Nam { get; set; } // To test scenario when Name.StartsWith(Nam) is true
- }
+ public string? Nam { get; set; } // To test scenario when Name.StartsWith(Nam) is true
+ }
- public class DependentPropertyContainer
- {
- public string Title { get; set; }
+ public class DependentPropertyContainer
+ {
+ public required string Title { get; set; }
- public SimpleObject Instance { get; set; }
- }
+ public required SimpleObject Instance { get; set; }
+ }
- public class SimpleType
- {
- public string String { get; set; }
- }
+ public class SimpleType
+ {
+ public required string String { get; set; }
+ }
- public class ClassWithRef
- {
- [Display(1)]
- public string String { get; set; }
- [Display(2)]
- public ClassWithRef Ref { get; set; }
- }
+ public class ClassWithRef
+ {
+ [Display(1)]
+ public required string String { get; set; }
+ [Display(2)]
+ public ClassWithRef? Ref { get; set; }
+ }
- public class ClassWithCollection
- {
- [Display(1)]
- public string String { get; set; }
- [Display(2)]
- public List List { get; set; } = new List();
- }
+ public class ClassWithCollection
+ {
+ [Display(1)]
+ public required string String { get; set; }
+ [Display(2)]
+ public List List { get; set; } = [];
+ }
- public class ClassWithRefCollection
- {
- [Display(1)]
- public string String { get; set; }
- [Display(2)]
- public List List { get; set; } = new List();
- }
+ public class ClassWithRefCollection
+ {
+ [Display(1)]
+ public required string String { get; set; }
+ [Display(2)]
+ public List List { get; set; } = [];
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Properties/AssemblyInfo.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Properties/AssemblyInfo.cs
index e4a851278e..771fc09ab3 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Properties/AssemblyInfo.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Properties/AssemblyInfo.cs
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System.Reflection;
-using System.Runtime.CompilerServices;
+
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Stride.Core.Presentation.Quantum.Tests.csproj b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Stride.Core.Presentation.Quantum.Tests.csproj
index 6f1197be1a..7a49c5adbe 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Stride.Core.Presentation.Quantum.Tests.csproj
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/Stride.Core.Presentation.Quantum.Tests.csproj
@@ -1,11 +1,16 @@
- $(StrideEditorTargetFramework)
+ $(StrideXplatEditorTargetFramework)
win-x64
+ enable
+ latest
+ enable
WindowsTools
- true
+
+
+
@@ -16,7 +21,6 @@
-
@@ -24,4 +28,4 @@
-
\ No newline at end of file
+
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestDependentProperties.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestDependentProperties.cs
index 2c42d29f98..00c360a1db 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestDependentProperties.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestDependentProperties.cs
@@ -1,247 +1,245 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using Xunit;
-using Stride.Core;
+
using Stride.Core.Presentation.Quantum.Presenters;
using Stride.Core.Presentation.Quantum.Tests.Helpers;
-namespace Stride.Core.Presentation.Quantum.Tests
-{
- // TODO: this class should be rewritten to properly match the new design of dependent properties, which is using hard-link between nodes instead of path-based.
- public class TestDependentProperties
- {
- private const string Title = nameof(Types.DependentPropertyContainer.Title);
- private const string Instance = nameof(Types.DependentPropertyContainer.Instance);
- private const string Name = nameof(Types.SimpleObject.Name);
- private const string Nam = nameof(Types.SimpleObject.Nam);
+namespace Stride.Core.Presentation.Quantum.Tests;
- private const string TestDataKey = "TestData";
- private const string UpdateCountKey = "UpdateCount";
- private static readonly PropertyKey TestData = new PropertyKey(TestDataKey, typeof(TestDependentProperties));
- private static readonly PropertyKey UpdateCount = new PropertyKey(UpdateCountKey, typeof(TestDependentProperties));
+// TODO: this class should be rewritten to properly match the new design of dependent properties, which is using hard-link between nodes instead of path-based.
+public class TestDependentProperties
+{
+ private const string Title = nameof(Types.DependentPropertyContainer.Title);
+ private const string Instance = nameof(Types.DependentPropertyContainer.Instance);
+ private const string Name = nameof(Types.SimpleObject.Name);
+ private const string Nam = nameof(Types.SimpleObject.Nam);
- private abstract class DependentPropertiesUpdater : NodePresenterUpdaterBase
- {
- private int count;
- protected abstract bool IsRecursive { get; }
+ private const string TestDataKey = "TestData";
+ private const string UpdateCountKey = "UpdateCount";
+ private static readonly PropertyKey TestData = new(TestDataKey, typeof(TestDependentProperties));
+ private static readonly PropertyKey UpdateCount = new(UpdateCountKey, typeof(TestDependentProperties));
- public override void UpdateNode(INodePresenter node)
- {
- if (node.Name == nameof(Types.DependentPropertyContainer.Title))
- {
- var instance = (Types.DependentPropertyContainer)node.Root.Value;
- node.AttachedProperties.Set(TestData, instance.Instance.Name);
- node.AttachedProperties.Set(UpdateCount, count++);
- }
- }
+ private abstract class DependentPropertiesUpdater : NodePresenterUpdaterBase
+ {
+ private int count;
+ protected abstract bool IsRecursive { get; }
- public override void FinalizeTree(INodePresenter root)
+ public override void UpdateNode(INodePresenter node)
+ {
+ if (node.Name == nameof(Types.DependentPropertyContainer.Title))
{
- var node = root[Title];
- var dependencyNode = GetDependencyNode(node.Root);
- node.AddDependency(dependencyNode, IsRecursive);
+ var instance = (Types.DependentPropertyContainer)node.Root.Value;
+ node.AttachedProperties.Set(TestData, instance.Instance.Name);
+ node.AttachedProperties.Set(UpdateCount, count++);
}
-
- protected abstract INodePresenter GetDependencyNode(INodePresenter rootNode);
}
- private class SimpleDependentPropertiesUpdater : DependentPropertiesUpdater
+ public override void FinalizeTree(INodePresenter root)
{
- protected override bool IsRecursive => false;
-
- protected override INodePresenter GetDependencyNode(INodePresenter rootNode)
- {
- return rootNode[Instance][Name];
- }
+ var node = root[Title];
+ var dependencyNode = GetDependencyNode(node.Root);
+ node.AddDependency(dependencyNode, IsRecursive);
}
- private class RecursiveDependentPropertiesUpdater : DependentPropertiesUpdater
- {
- protected override bool IsRecursive => true;
+ protected abstract INodePresenter GetDependencyNode(INodePresenter rootNode);
+ }
- protected override INodePresenter GetDependencyNode(INodePresenter rootNode)
- {
- return rootNode[Instance];
- }
- }
+ private class SimpleDependentPropertiesUpdater : DependentPropertiesUpdater
+ {
+ protected override bool IsRecursive => false;
- [Fact]
- public void TestSimpleDependency()
+ protected override INodePresenter GetDependencyNode(INodePresenter rootNode)
{
- var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
- var testContext = new TestContainerContext();
- var instanceContext = testContext.CreateInstanceContext(container);
- testContext.GraphViewModelService.AvailableUpdaters.Add(new SimpleDependentPropertiesUpdater());
- var viewModel = instanceContext.CreateViewModel();
- var titleNode = viewModel.RootNode.GetChild(Title);
- var nameNode = viewModel.RootNode.GetChild(Instance).GetChild(Name);
-
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue2";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+ return rootNode[Instance][Name];
}
+ }
- [Fact(Skip = "Review why this test is failing and refactor to match new design of dependent properties.")]
- public void TestSimpleDependencyChangeParent()
- {
- var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
- var testContext = new TestContainerContext();
- var instanceContext = testContext.CreateInstanceContext(container);
- testContext.GraphViewModelService.AvailableUpdaters.Add(new SimpleDependentPropertiesUpdater());
- var viewModel = instanceContext.CreateViewModel();
- var titleNode = viewModel.RootNode.GetChild(Title);
- var instanceNode = viewModel.RootNode.GetChild(Instance);
-
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue" };
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue2" };
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
- }
+ private class RecursiveDependentPropertiesUpdater : DependentPropertiesUpdater
+ {
+ protected override bool IsRecursive => true;
- [Fact]
- public void TestRecursiveDependency()
+ protected override INodePresenter GetDependencyNode(INodePresenter rootNode)
{
- var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
- var testContext = new TestContainerContext();
- var instanceContext = testContext.CreateInstanceContext(container);
- testContext.GraphViewModelService.AvailableUpdaters.Add(new RecursiveDependentPropertiesUpdater());
- var viewModel = instanceContext.CreateViewModel();
- var titleNode = viewModel.RootNode.GetChild(Title);
- var instanceNode = viewModel.RootNode.GetChild(Instance);
-
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue" };
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue2" };
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+ return rootNode[Instance];
}
+ }
- [Fact(Skip = "Review why this test is failing and refactor to match new design of dependent properties.")]
- public void TestRecursiveDependencyChangeChild()
- {
- var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
- var testContext = new TestContainerContext();
- var instanceContext = testContext.CreateInstanceContext(container);
- testContext.GraphViewModelService.AvailableUpdaters.Add(new RecursiveDependentPropertiesUpdater());
- var viewModel = instanceContext.CreateViewModel();
- var titleNode = viewModel.RootNode.GetChild(Title);
- var nameNode = viewModel.RootNode.GetChild(Instance).GetChild(Name);
-
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue2";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
- }
+ [Fact]
+ public void TestSimpleDependency()
+ {
+ var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
+ var testContext = new TestContainerContext();
+ var instanceContext = testContext.CreateInstanceContext(container);
+ testContext.GraphViewModelService.AvailableUpdaters.Add(new SimpleDependentPropertiesUpdater());
+ var viewModel = instanceContext.CreateViewModel();
+ var titleNode = viewModel.RootNode.GetChild(Title)!;
+ var nameNode = viewModel.RootNode.GetChild(Instance)!.GetChild(Name)!;
+
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue2";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+ }
- [Fact(Skip = "Review why this test is failing and refactor to match new design of dependent properties.")]
- public void TestRecursiveDependencyMixedChanges()
- {
- var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
- var testContext = new TestContainerContext();
- var instanceContext = testContext.CreateInstanceContext(container);
- testContext.GraphViewModelService.AvailableUpdaters.Add(new RecursiveDependentPropertiesUpdater());
- var viewModel = instanceContext.CreateViewModel();
- var titleNode = viewModel.RootNode.GetChild(Title);
- var instanceNode = viewModel.RootNode.GetChild(Instance);
-
- var nameNode = viewModel.RootNode.GetChild(Instance).GetChild(Name);
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue2" };
- nameNode = viewModel.RootNode.GetChild(Instance).GetChild(Name);
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue3";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue3", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(3, titleNode.AssociatedData[UpdateCountKey]);
-
- instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue4" };
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue4", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(4, titleNode.AssociatedData[UpdateCountKey]);
- }
+ [Fact(Skip = "Review why this test is failing and refactor to match new design of dependent properties.")]
+ public void TestSimpleDependencyChangeParent()
+ {
+ var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
+ var testContext = new TestContainerContext();
+ var instanceContext = testContext.CreateInstanceContext(container);
+ testContext.GraphViewModelService.AvailableUpdaters.Add(new SimpleDependentPropertiesUpdater());
+ var viewModel = instanceContext.CreateViewModel();
+ var titleNode = viewModel.RootNode.GetChild(Title)!;
+ var instanceNode = viewModel.RootNode.GetChild(Instance)!;
+
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue" };
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue2" };
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+ }
- [Fact]
- public void TestChangeDifferentPropertyWithSameStart()
- {
- var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
- var testContext = new TestContainerContext();
- var instanceContext = testContext.CreateInstanceContext(container);
- testContext.GraphViewModelService.AvailableUpdaters.Add(new SimpleDependentPropertiesUpdater());
- var viewModel = instanceContext.CreateViewModel();
- var titleNode = viewModel.RootNode.GetChild(Title);
- var nameNode = viewModel.RootNode.GetChild(Instance).GetChild(Name);
- var namNode = viewModel.RootNode.GetChild(Instance).GetChild(Nam);
-
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- namNode.NodeValue = "NewValue";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue2";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- namNode.NodeValue = "NewValue3";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
-
- nameNode.NodeValue = "NewValue4";
- Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
- Assert.Equal("NewValue4", titleNode.AssociatedData[TestDataKey]);
- Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
- }
+ [Fact]
+ public void TestRecursiveDependency()
+ {
+ var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
+ var testContext = new TestContainerContext();
+ var instanceContext = testContext.CreateInstanceContext(container);
+ testContext.GraphViewModelService.AvailableUpdaters.Add(new RecursiveDependentPropertiesUpdater());
+ var viewModel = instanceContext.CreateViewModel();
+ var titleNode = viewModel.RootNode.GetChild(Title)!;
+ var instanceNode = viewModel.RootNode.GetChild(Instance)!;
+
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue" };
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue2" };
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+ }
+
+ [Fact(Skip = "Review why this test is failing and refactor to match new design of dependent properties.")]
+ public void TestRecursiveDependencyChangeChild()
+ {
+ var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
+ var testContext = new TestContainerContext();
+ var instanceContext = testContext.CreateInstanceContext(container);
+ testContext.GraphViewModelService.AvailableUpdaters.Add(new RecursiveDependentPropertiesUpdater());
+ var viewModel = instanceContext.CreateViewModel();
+ var titleNode = viewModel.RootNode.GetChild(Title)!;
+ var nameNode = viewModel.RootNode.GetChild(Instance)!.GetChild(Name)!;
+
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue2";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+ }
+
+ [Fact(Skip = "Review why this test is failing and refactor to match new design of dependent properties.")]
+ public void TestRecursiveDependencyMixedChanges()
+ {
+ var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
+ var testContext = new TestContainerContext();
+ var instanceContext = testContext.CreateInstanceContext(container);
+ testContext.GraphViewModelService.AvailableUpdaters.Add(new RecursiveDependentPropertiesUpdater());
+ var viewModel = instanceContext.CreateViewModel();
+ var titleNode = viewModel.RootNode.GetChild(Title)!;
+ var instanceNode = viewModel.RootNode.GetChild(Instance)!;
+
+ var nameNode = viewModel.RootNode.GetChild(Instance)!.GetChild(Name)!;
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue2" };
+ nameNode = viewModel.RootNode.GetChild(Instance)!.GetChild(Name)!;
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue3";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue3", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(3, titleNode.AssociatedData[UpdateCountKey]);
+
+ instanceNode.NodeValue = new Types.SimpleObject { Name = "NewValue4" };
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue4", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(4, titleNode.AssociatedData[UpdateCountKey]);
+ }
+
+ [Fact]
+ public void TestChangeDifferentPropertyWithSameStart()
+ {
+ var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
+ var testContext = new TestContainerContext();
+ var instanceContext = testContext.CreateInstanceContext(container);
+ testContext.GraphViewModelService.AvailableUpdaters.Add(new SimpleDependentPropertiesUpdater());
+ var viewModel = instanceContext.CreateViewModel();
+ var titleNode = viewModel.RootNode.GetChild(Title)!;
+ var nameNode = viewModel.RootNode.GetChild(Instance)!.GetChild(Name)!;
+ var namNode = viewModel.RootNode.GetChild(Instance)!.GetChild(Nam)!;
+
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ namNode.NodeValue = "NewValue";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("Test", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(0, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue2";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ namNode.NodeValue = "NewValue3";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue2", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(1, titleNode.AssociatedData[UpdateCountKey]);
+
+ nameNode.NodeValue = "NewValue4";
+ Assert.True(titleNode.AssociatedData.ContainsKey(TestDataKey));
+ Assert.Equal("NewValue4", titleNode.AssociatedData[TestDataKey]);
+ Assert.Equal(2, titleNode.AssociatedData[UpdateCountKey]);
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterProperties.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterProperties.cs
index 4c7ff53e37..d3e49c1c03 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterProperties.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterProperties.cs
@@ -1,182 +1,179 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System.Collections.Generic;
-using Xunit;
-using Stride.Core;
+
using Stride.Core.Presentation.Quantum.Tests.Helpers;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum.Tests
+namespace Stride.Core.Presentation.Quantum.Tests;
+
+public class TestNodePresenterProperties
{
- public class TestNodePresenterProperties
+ [DataContract]
+ public class SimpleMember
{
- [DataContract]
- public class SimpleMember
- {
- public float FloatValue { get; set; }
- }
+ public float FloatValue { get; set; }
+ }
- [DataContract]
- public class SimpleMemberWithContract
- {
- [DataMember(10)]
- public float FloatValue { get; set; }
- }
+ [DataContract]
+ public class SimpleMemberWithContract
+ {
+ [DataMember(10)]
+ public float FloatValue { get; set; }
+ }
- public class NestedMemberClass
- {
- [DataMember(20)]
- public SimpleMemberWithContract MemberClass { get; set; } = new SimpleMemberWithContract();
- }
+ public class NestedMemberClass
+ {
+ [DataMember(20)]
+ public SimpleMemberWithContract MemberClass { get; set; } = new SimpleMemberWithContract();
+ }
- public class NestedReadonlyMemberClass
- {
- [DataMember(30)]
- public SimpleMemberWithContract MemberClass { get; } = new SimpleMemberWithContract();
- }
+ public class NestedReadonlyMemberClass
+ {
+ [DataMember(30)]
+ public SimpleMemberWithContract MemberClass { get; } = new SimpleMemberWithContract();
+ }
- public class ListMember
- {
- [DataMember(40)]
- public List List { get; set; }
- }
+ public class ListMember
+ {
+ [DataMember(40)]
+ public List? List { get; set; }
+ }
- [Fact]
- public void TestSimpleMember()
- {
- var instance = new SimpleMember { FloatValue = 1.0f };
- var context = BuildContext(instance);
- var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
- var member = root[nameof(SimpleMember.FloatValue)];
- Assert.Equal(0, member.Children.Count);
- Assert.Equal(nameof(SimpleMember.FloatValue), member.DisplayName);
- Assert.Equal(NodeIndex.Empty, member.Index);
- Assert.False(member.IsEnumerable);
- Assert.False(member.IsReadOnly);
- Assert.True(member.IsVisible);
- Assert.Equal(nameof(SimpleMember.FloatValue), member.Name);
- Assert.Null(member.Order);
- Assert.Equal(root, member.Parent);
- Assert.Equal(1.0f, member.Value);
- }
+ [Fact]
+ public void TestSimpleMember()
+ {
+ var instance = new SimpleMember { FloatValue = 1.0f };
+ var context = BuildContext(instance);
+ var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+ var member = root[nameof(SimpleMember.FloatValue)];
+ Assert.Empty(member.Children);
+ Assert.Equal(nameof(SimpleMember.FloatValue), member.DisplayName);
+ Assert.Equal(NodeIndex.Empty, member.Index);
+ Assert.False(member.IsEnumerable);
+ Assert.False(member.IsReadOnly);
+ Assert.True(member.IsVisible);
+ Assert.Equal(nameof(SimpleMember.FloatValue), member.Name);
+ Assert.Null(member.Order);
+ Assert.Equal(root, member.Parent);
+ Assert.Equal(1.0f, member.Value);
+ }
- [Fact]
- public void TestSimpleMemberWithContract()
- {
- var instance = new SimpleMemberWithContract { FloatValue = 1.0f };
- var context = BuildContext(instance);
- var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
- var member = root[nameof(SimpleMember.FloatValue)];
- Assert.Equal(0, member.Children.Count);
- Assert.Equal(nameof(SimpleMember.FloatValue), member.DisplayName);
- Assert.Equal(NodeIndex.Empty, member.Index);
- Assert.False(member.IsEnumerable);
- Assert.False(member.IsReadOnly);
- Assert.True(member.IsVisible);
- Assert.Equal(nameof(SimpleMember.FloatValue), member.Name);
- Assert.Equal(10, member.Order);
- Assert.Equal(root, member.Parent);
- Assert.Equal(1.0f, member.Value);
- }
+ [Fact]
+ public void TestSimpleMemberWithContract()
+ {
+ var instance = new SimpleMemberWithContract { FloatValue = 1.0f };
+ var context = BuildContext(instance);
+ var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+ var member = root[nameof(SimpleMember.FloatValue)];
+ Assert.Empty(member.Children);
+ Assert.Equal(nameof(SimpleMember.FloatValue), member.DisplayName);
+ Assert.Equal(NodeIndex.Empty, member.Index);
+ Assert.False(member.IsEnumerable);
+ Assert.False(member.IsReadOnly);
+ Assert.True(member.IsVisible);
+ Assert.Equal(nameof(SimpleMember.FloatValue), member.Name);
+ Assert.Equal(10, member.Order);
+ Assert.Equal(root, member.Parent);
+ Assert.Equal(1.0f, member.Value);
+ }
- [Fact]
- public void TestNestedMember()
- {
- var instance = new NestedMemberClass { MemberClass = { FloatValue = 1.0f } };
- var context = BuildContext(instance);
- var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
- var member = root[nameof(NestedMemberClass.MemberClass)];
- Assert.Equal(1, member.Children.Count);
- Assert.Equal(nameof(NestedMemberClass.MemberClass), member.DisplayName);
- Assert.Equal(NodeIndex.Empty, member.Index);
- Assert.False(member.IsEnumerable);
- Assert.False(member.IsReadOnly);
- Assert.True(member.IsVisible);
- Assert.Equal(nameof(NestedMemberClass.MemberClass), member.Name);
- Assert.Equal(20, member.Order);
- Assert.Equal(root, member.Parent);
- Assert.Equal(instance.MemberClass, member.Value);
- var innerMember = member[nameof(SimpleMember.FloatValue)];
- Assert.Equal(0, innerMember.Children.Count);
- Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.DisplayName);
- Assert.Equal(NodeIndex.Empty, innerMember.Index);
- Assert.False(innerMember.IsEnumerable);
- Assert.False(innerMember.IsReadOnly);
- Assert.True(innerMember.IsVisible);
- Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.Name);
- Assert.Equal(10, innerMember.Order);
- Assert.Equal(member, innerMember.Parent);
- Assert.Equal(1.0f, innerMember.Value);
- }
+ [Fact]
+ public void TestNestedMember()
+ {
+ var instance = new NestedMemberClass { MemberClass = { FloatValue = 1.0f } };
+ var context = BuildContext(instance);
+ var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+ var member = root[nameof(NestedMemberClass.MemberClass)];
+ Assert.Single(member.Children);
+ Assert.Equal(nameof(NestedMemberClass.MemberClass), member.DisplayName);
+ Assert.Equal(NodeIndex.Empty, member.Index);
+ Assert.False(member.IsEnumerable);
+ Assert.False(member.IsReadOnly);
+ Assert.True(member.IsVisible);
+ Assert.Equal(nameof(NestedMemberClass.MemberClass), member.Name);
+ Assert.Equal(20, member.Order);
+ Assert.Equal(root, member.Parent);
+ Assert.Equal(instance.MemberClass, member.Value);
+ var innerMember = member[nameof(SimpleMember.FloatValue)];
+ Assert.Empty(innerMember.Children);
+ Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.DisplayName);
+ Assert.Equal(NodeIndex.Empty, innerMember.Index);
+ Assert.False(innerMember.IsEnumerable);
+ Assert.False(innerMember.IsReadOnly);
+ Assert.True(innerMember.IsVisible);
+ Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.Name);
+ Assert.Equal(10, innerMember.Order);
+ Assert.Equal(member, innerMember.Parent);
+ Assert.Equal(1.0f, innerMember.Value);
+ }
- [Fact]
- public void TestNestedReadOnlyMember()
- {
- var instance = new NestedReadonlyMemberClass { MemberClass = { FloatValue = 1.0f } };
- var context = BuildContext(instance);
- var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
- var member = root[nameof(NestedMemberClass.MemberClass)];
- Assert.Equal(1, member.Children.Count);
- Assert.Equal(nameof(NestedMemberClass.MemberClass), member.DisplayName);
- Assert.Equal(NodeIndex.Empty, member.Index);
- Assert.False(member.IsEnumerable);
- Assert.True(member.IsReadOnly);
- Assert.True(member.IsVisible);
- Assert.Equal(nameof(NestedMemberClass.MemberClass), member.Name);
- Assert.Equal(30, member.Order);
- Assert.Equal(root, member.Parent);
- Assert.Equal(instance.MemberClass, member.Value);
- var innerMember = member[nameof(SimpleMember.FloatValue)];
- Assert.Equal(0, innerMember.Children.Count);
- Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.DisplayName);
- Assert.Equal(NodeIndex.Empty, innerMember.Index);
- Assert.False(innerMember.IsEnumerable);
- Assert.False(innerMember.IsReadOnly);
- Assert.True(innerMember.IsVisible);
- Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.Name);
- Assert.Equal(10, innerMember.Order);
- Assert.Equal(member, innerMember.Parent);
- Assert.Equal(1.0f, innerMember.Value);
- }
+ [Fact]
+ public void TestNestedReadOnlyMember()
+ {
+ var instance = new NestedReadonlyMemberClass { MemberClass = { FloatValue = 1.0f } };
+ var context = BuildContext(instance);
+ var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+ var member = root[nameof(NestedMemberClass.MemberClass)];
+ Assert.Single(member.Children);
+ Assert.Equal(nameof(NestedMemberClass.MemberClass), member.DisplayName);
+ Assert.Equal(NodeIndex.Empty, member.Index);
+ Assert.False(member.IsEnumerable);
+ Assert.True(member.IsReadOnly);
+ Assert.True(member.IsVisible);
+ Assert.Equal(nameof(NestedMemberClass.MemberClass), member.Name);
+ Assert.Equal(30, member.Order);
+ Assert.Equal(root, member.Parent);
+ Assert.Equal(instance.MemberClass, member.Value);
+ var innerMember = member[nameof(SimpleMember.FloatValue)];
+ Assert.Empty(innerMember.Children);
+ Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.DisplayName);
+ Assert.Equal(NodeIndex.Empty, innerMember.Index);
+ Assert.False(innerMember.IsEnumerable);
+ Assert.False(innerMember.IsReadOnly);
+ Assert.True(innerMember.IsVisible);
+ Assert.Equal(nameof(SimpleMember.FloatValue), innerMember.Name);
+ Assert.Equal(10, innerMember.Order);
+ Assert.Equal(member, innerMember.Parent);
+ Assert.Equal(1.0f, innerMember.Value);
+ }
- [Fact]
- public void TestListMember()
- {
- var instance = new ListMember { List = new List() };
- var context = BuildContext(instance);
- var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
- var member = root[nameof(ListMember.List)];
- Assert.Equal(0, member.Children.Count);
- Assert.Equal(nameof(ListMember.List), member.DisplayName);
- Assert.Equal(NodeIndex.Empty, member.Index);
- Assert.True(member.IsEnumerable);
- Assert.False(member.IsReadOnly);
- Assert.True(member.IsVisible);
- Assert.Equal(nameof(ListMember.List), member.Name);
- Assert.Equal(40, member.Order);
- Assert.Equal(root, member.Parent);
- Assert.Equal(instance.List, member.Value);
+ [Fact]
+ public void TestListMember()
+ {
+ var instance = new ListMember { List = [] };
+ var context = BuildContext(instance);
+ var root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+ var member = root[nameof(ListMember.List)];
+ Assert.Empty(member.Children);
+ Assert.Equal(nameof(ListMember.List), member.DisplayName);
+ Assert.Equal(NodeIndex.Empty, member.Index);
+ Assert.True(member.IsEnumerable);
+ Assert.False(member.IsReadOnly);
+ Assert.True(member.IsVisible);
+ Assert.Equal(nameof(ListMember.List), member.Name);
+ Assert.Equal(40, member.Order);
+ Assert.Equal(root, member.Parent);
+ Assert.Equal(instance.List, member.Value);
- instance = new ListMember();
- context = BuildContext(instance);
- root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
- member = root[nameof(ListMember.List)];
- Assert.Equal(0, member.Children.Count);
- Assert.Equal(nameof(ListMember.List), member.DisplayName);
- Assert.Equal(NodeIndex.Empty, member.Index);
- Assert.False(member.IsEnumerable);
- Assert.False(member.IsReadOnly);
- Assert.True(member.IsVisible);
- Assert.Equal(nameof(ListMember.List), member.Name);
- Assert.Equal(40, member.Order);
- Assert.Equal(root, member.Parent);
- Assert.Equal(instance.List, member.Value);
- }
+ instance = new ListMember();
+ context = BuildContext(instance);
+ root = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+ member = root[nameof(ListMember.List)];
+ Assert.Empty(member.Children);
+ Assert.Equal(nameof(ListMember.List), member.DisplayName);
+ Assert.Equal(NodeIndex.Empty, member.Index);
+ Assert.False(member.IsEnumerable);
+ Assert.False(member.IsReadOnly);
+ Assert.True(member.IsVisible);
+ Assert.Equal(nameof(ListMember.List), member.Name);
+ Assert.Equal(40, member.Order);
+ Assert.Equal(root, member.Parent);
+ Assert.Equal(instance.List, member.Value);
+ }
- private static TestInstanceContext BuildContext(object instance)
- {
- var context = new TestContainerContext();
- return context.CreateInstanceContext(instance);
- }
+ private static TestInstanceContext BuildContext(object instance)
+ {
+ var context = new TestContainerContext();
+ return context.CreateInstanceContext(instance);
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterUpdates.cs b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterUpdates.cs
index c31b35beef..83decbba42 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterUpdates.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum.Tests/TestNodePresenterUpdates.cs
@@ -1,485 +1,482 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System.Collections.Generic;
-using System.Linq;
-using Xunit;
+
using Stride.Core.Presentation.Quantum.Tests.Helpers;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum.Tests
+namespace Stride.Core.Presentation.Quantum.Tests;
+
+public class TestNodePresenterUpdates
{
- public class TestNodePresenterUpdates
+ [Fact]
+ public void TestPrimitiveMemberUpdate()
+ {
+ var instance = new Types.SimpleType { String = "aaa" };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter.Children.Single().UpdateValue("bbb");
+ Assert.Single(presenter.Children);
+ var child = presenter.Children.Single();
+ Assert.Equal("String", child.Name);
+ Assert.Equal(presenter, child.Parent);
+ Assert.Empty(child.Children);
+ Assert.Equal(typeof(string), child.Type);
+ Assert.Equal("bbb", child.Value);
+
+ presenter.Children.Single().UpdateValue("ccc");
+ Assert.Single(presenter.Children);
+ child = presenter.Children.Single();
+ Assert.Equal("String", child.Name);
+ Assert.Equal(presenter, child.Parent);
+ Assert.Empty(child.Children);
+ Assert.Equal(typeof(string), child.Type);
+ Assert.Equal("ccc", child.Value);
+ }
+
+ [Fact]
+ public void TestReferenceMemberUpdate()
+ {
+ var instance = new Types.ClassWithRef { String = "aaa", Ref = new Types.ClassWithRef { String = "bbb" } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter.Children[1].UpdateValue(new Types.ClassWithRef { String = "ccc" });
+ Assert.Equal(2, presenter.Children.Count);
+ Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
+ Assert.Equal(instance.Ref, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
+ Assert.Equal(instance.Ref, presenter.Children[1].Value);
+ Assert.Equal("String", presenter.Children[1].Children[0].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
+ Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Children[1].Type);
+ Assert.Equal(instance.Ref.Ref, presenter.Children[1].Children[1].Value);
+
+ presenter.Children[1].UpdateValue(new Types.ClassWithRef { String = "ddd" });
+ Assert.Equal(2, presenter.Children.Count);
+ Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
+ Assert.Equal(instance.Ref, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
+ Assert.Equal(instance.Ref, presenter.Children[1].Value);
+ Assert.Equal("String", presenter.Children[1].Children[0].Name);
+ Assert.Equal("ddd", presenter.Children[1].Children[0].Value);
+ Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Children[1].Type);
+ Assert.Equal(instance.Ref.Ref, presenter.Children[1].Children[1].Value);
+ }
+
+ [Fact]
+ public void TestPrimitiveListUpdate()
+ {
+ var instance = new Types.ClassWithCollection { String = "aaa", List = { "bbb", "ccc" } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter[nameof(Types.ClassWithCollection.List)].Children[1].UpdateValue("ddd");
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[1].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+
+ presenter[nameof(Types.ClassWithCollection.List)].Children[1].UpdateValue("eee");
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+
+ presenter[nameof(Types.ClassWithCollection.List)].Children[0].UpdateValue("fff");
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("fff", presenter.Children[1].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ }
+
+ [Fact]
+ public void TestPrimitiveListAdd()
+ {
+ var instance = new Types.ClassWithCollection { String = "aaa", List = { "bbb", "ccc" } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter.Children[1].AddItem("ddd", new NodeIndex(2));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(3, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[1].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[2].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+
+ presenter.Children[1].AddItem("eee", new NodeIndex(1));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(4, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("3", presenter.Children[1].Children[3].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[2].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[3].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[3].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+ Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
+
+ presenter.Children[1].AddItem("fff", new NodeIndex(0));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(5, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("3", presenter.Children[1].Children[3].Name);
+ Assert.Equal("4", presenter.Children[1].Children[4].Name);
+ Assert.Equal("fff", presenter.Children[1].Children[0].Value);
+ Assert.Equal("bbb", presenter.Children[1].Children[1].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[2].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[3].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[4].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[3].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[4].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+ Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
+ Assert.Equal(instance.List[4], presenter.Children[1].Children[4].Value);
+ }
+
+ [Fact]
+ public void TestPrimitiveListRemove()
+ {
+ var instance = new Types.ClassWithCollection { String = "aaa", List = { "bbb", "ccc", "ddd", "eee", "fff" } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter.Children[1].RemoveItem("fff", new NodeIndex(4));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(4, presenter.Children[1].Children.Count);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("3", presenter.Children[1].Children[3].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[1].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[2].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[3].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[3].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+ Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
+
+ presenter.Children[1].RemoveItem("bbb", new NodeIndex(0));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(3, presenter.Children[1].Children.Count);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[1].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[2].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+
+ presenter.Children[1].RemoveItem("ddd", new NodeIndex(1));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+
+ presenter.Children[1].RemoveItem("eee", new NodeIndex(1));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Single(presenter.Children[1].Children);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+
+ presenter.Children[1].RemoveItem("ccc", new NodeIndex(0));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Empty(presenter.Children[1].Children);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ }
+
+ [Fact]
+ public void TestReferenceListUpdate()
+ {
+ var instance = new Types.ClassWithRefCollection { String = "aaa", List = { new Types.SimpleType { String = "bbb" }, new Types.SimpleType { String = "ccc" } } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter[nameof(Types.ClassWithRefCollection.List)].Children[1].UpdateValue(new Types.SimpleType { String = "ddd" });
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+
+ presenter[nameof(Types.ClassWithRefCollection.List)].Children[1].UpdateValue(new Types.SimpleType { String = "eee" });
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+
+ presenter[nameof(Types.ClassWithRefCollection.List)].Children[0].UpdateValue(new Types.SimpleType { String = "fff" });
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("fff", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ }
+
+ [Fact]
+ public void TestReferenceListAdd()
+ {
+ var instance = new Types.ClassWithRefCollection { String = "aaa", List = { new Types.SimpleType { String = "bbb" }, new Types.SimpleType { String = "ccc" } } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter.Children[1].AddItem(new Types.SimpleType { String = "ddd" }, new NodeIndex(2));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(3, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[2].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+
+ presenter.Children[1].AddItem(new Types.SimpleType { String = "eee" }, new NodeIndex(1));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(4, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("3", presenter.Children[1].Children[3].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[2].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[3].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[3].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[3].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+ Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
+
+ presenter.Children[1].AddItem(new Types.SimpleType { String = "fff" }, new NodeIndex(0));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal(5, presenter.Children[1].Children.Count);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("3", presenter.Children[1].Children[3].Name);
+ Assert.Equal("4", presenter.Children[1].Children[4].Name);
+ Assert.Equal("fff", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("bbb", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[2].Children[0].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[3].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[4].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[3].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[4].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[3].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[4].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+ Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
+ Assert.Equal(instance.List[4], presenter.Children[1].Children[4].Value);
+ }
+
+ [Fact]
+ public void TestReferenceListRemove()
+ {
+ var instance = new Types.ClassWithRefCollection { String = "aaa", List = { new Types.SimpleType { String = "bbb" }, new Types.SimpleType { String = "ccc" }, new Types.SimpleType { String = "ddd" }, new Types.SimpleType { String = "eee" }, new Types.SimpleType { String = "fff" }, } };
+ var context = BuildContext(instance);
+ var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
+
+ presenter.Children[1].RemoveItem(instance.List[4], new NodeIndex(4));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(4, presenter.Children[1].Children.Count);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("ccc", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[2].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[3].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[3].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[3].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+ Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
+
+ presenter.Children[1].RemoveItem("bbb", new NodeIndex(0));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(3, presenter.Children[1].Children.Count);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("2", presenter.Children[1].Children[2].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("ddd", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[2].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+ Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
+
+ presenter.Children[1].RemoveItem("ddd", new NodeIndex(1));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Equal(2, presenter.Children[1].Children.Count);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("1", presenter.Children[1].Children[1].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+ Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
+
+ presenter.Children[1].RemoveItem("eee", new NodeIndex(1));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Single(presenter.Children[1].Children);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ Assert.Equal("0", presenter.Children[1].Children[0].Name);
+ Assert.Equal("ccc", presenter.Children[1].Children[0].Children[0].Value);
+ Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
+ Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
+ Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
+
+ presenter.Children[1].RemoveItem("ccc", new NodeIndex(0));
+ Assert.Equal(typeof(List), presenter.Children[1].Type);
+ Assert.Empty(presenter.Children[1].Children);
+ Assert.Equal(instance.List, presenter.Children[1].Value);
+ }
+
+ private static TestInstanceContext BuildContext(object instance)
{
- [Fact]
- public void TestPrimitiveMemberUpdate()
- {
- var instance = new Types.SimpleType { String = "aaa" };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter.Children.Single().UpdateValue("bbb");
- Assert.Equal(1, presenter.Children.Count);
- var child = presenter.Children.Single();
- Assert.Equal("String", child.Name);
- Assert.Equal(presenter, child.Parent);
- Assert.Equal(0, child.Children.Count);
- Assert.Equal(typeof(string), child.Type);
- Assert.Equal("bbb", child.Value);
-
- presenter.Children.Single().UpdateValue("ccc");
- Assert.Equal(1, presenter.Children.Count);
- child = presenter.Children.Single();
- Assert.Equal("String", child.Name);
- Assert.Equal(presenter, child.Parent);
- Assert.Equal(0, child.Children.Count);
- Assert.Equal(typeof(string), child.Type);
- Assert.Equal("ccc", child.Value);
- }
-
- [Fact]
- public void TestReferenceMemberUpdate()
- {
- var instance = new Types.ClassWithRef { String = "aaa", Ref = new Types.ClassWithRef { String = "bbb" } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter.Children[1].UpdateValue(new Types.ClassWithRef { String = "ccc" });
- Assert.Equal(2, presenter.Children.Count);
- Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
- Assert.Equal(instance.Ref, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
- Assert.Equal(instance.Ref, presenter.Children[1].Value);
- Assert.Equal("String", presenter.Children[1].Children[0].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
- Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Children[1].Type);
- Assert.Equal(instance.Ref.Ref, presenter.Children[1].Children[1].Value);
-
- presenter.Children[1].UpdateValue(new Types.ClassWithRef { String = "ddd" });
- Assert.Equal(2, presenter.Children.Count);
- Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
- Assert.Equal(instance.Ref, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Type);
- Assert.Equal(instance.Ref, presenter.Children[1].Value);
- Assert.Equal("String", presenter.Children[1].Children[0].Name);
- Assert.Equal("ddd", presenter.Children[1].Children[0].Value);
- Assert.Equal(typeof(Types.ClassWithRef), presenter.Children[1].Children[1].Type);
- Assert.Equal(instance.Ref.Ref, presenter.Children[1].Children[1].Value);
- }
-
- [Fact]
- public void TestPrimitiveListUpdate()
- {
- var instance = new Types.ClassWithCollection { String = "aaa", List = { "bbb", "ccc" } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter[nameof(Types.ClassWithCollection.List)].Children[1].UpdateValue("ddd");
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[1].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
-
- presenter[nameof(Types.ClassWithCollection.List)].Children[1].UpdateValue("eee");
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
-
- presenter[nameof(Types.ClassWithCollection.List)].Children[0].UpdateValue("fff");
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("fff", presenter.Children[1].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- }
-
- [Fact]
- public void TestPrimitiveListAdd()
- {
- var instance = new Types.ClassWithCollection { String = "aaa", List = { "bbb", "ccc" } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter.Children[1].AddItem("ddd", new NodeIndex(2));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(3, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[1].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[2].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
-
- presenter.Children[1].AddItem("eee", new NodeIndex(1));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(4, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("3", presenter.Children[1].Children[3].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[2].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[3].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[3].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
- Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
-
- presenter.Children[1].AddItem("fff", new NodeIndex(0));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(5, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("3", presenter.Children[1].Children[3].Name);
- Assert.Equal("4", presenter.Children[1].Children[4].Name);
- Assert.Equal("fff", presenter.Children[1].Children[0].Value);
- Assert.Equal("bbb", presenter.Children[1].Children[1].Value);
- Assert.Equal("eee", presenter.Children[1].Children[2].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[3].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[4].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[3].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[4].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
- Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
- Assert.Equal(instance.List[4], presenter.Children[1].Children[4].Value);
- }
-
- [Fact]
- public void TestPrimitiveListRemove()
- {
- var instance = new Types.ClassWithCollection { String = "aaa", List = { "bbb", "ccc", "ddd", "eee", "fff" } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter.Children[1].RemoveItem("fff", new NodeIndex(4));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(4, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("3", presenter.Children[1].Children[3].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[1].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[2].Value);
- Assert.Equal("eee", presenter.Children[1].Children[3].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[3].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
- Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
-
- presenter.Children[1].RemoveItem("bbb", new NodeIndex(0));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(3, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[1].Value);
- Assert.Equal("eee", presenter.Children[1].Children[2].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
-
- presenter.Children[1].RemoveItem("ddd", new NodeIndex(1));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
-
- presenter.Children[1].RemoveItem("eee", new NodeIndex(1));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(1, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Value);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
-
- presenter.Children[1].RemoveItem("ccc", new NodeIndex(0));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(0, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- }
-
- [Fact]
- public void TestReferenceListUpdate()
- {
- var instance = new Types.ClassWithRefCollection { String = "aaa", List = { new Types.SimpleType { String = "bbb" }, new Types.SimpleType { String = "ccc" } } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter[nameof(Types.ClassWithRefCollection.List)].Children[1].UpdateValue(new Types.SimpleType { String = "ddd" });
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
-
- presenter[nameof(Types.ClassWithRefCollection.List)].Children[1].UpdateValue(new Types.SimpleType { String = "eee" });
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
-
- presenter[nameof(Types.ClassWithRefCollection.List)].Children[0].UpdateValue(new Types.SimpleType { String = "fff" });
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("fff", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- }
-
- [Fact]
- public void TestReferenceListAdd()
- {
- var instance = new Types.ClassWithRefCollection { String = "aaa", List = { new Types.SimpleType { String = "bbb" }, new Types.SimpleType { String = "ccc" } } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter.Children[1].AddItem(new Types.SimpleType { String = "ddd" }, new NodeIndex(2));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(3, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[2].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
-
- presenter.Children[1].AddItem(new Types.SimpleType { String = "eee" }, new NodeIndex(1));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(4, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("3", presenter.Children[1].Children[3].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[2].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[3].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[3].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[3].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
- Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
-
- presenter.Children[1].AddItem(new Types.SimpleType { String = "fff" }, new NodeIndex(0));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal(5, presenter.Children[1].Children.Count);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("3", presenter.Children[1].Children[3].Name);
- Assert.Equal("4", presenter.Children[1].Children[4].Name);
- Assert.Equal("fff", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("bbb", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[2].Children[0].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[3].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[4].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[3].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[4].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[3].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[4].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
- Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
- Assert.Equal(instance.List[4], presenter.Children[1].Children[4].Value);
- }
-
- [Fact]
- public void TestReferenceListRemove()
- {
- var instance = new Types.ClassWithRefCollection { String = "aaa", List = { new Types.SimpleType { String = "bbb" }, new Types.SimpleType { String = "ccc" }, new Types.SimpleType { String = "ddd" }, new Types.SimpleType { String = "eee" }, new Types.SimpleType { String = "fff" }, } };
- var context = BuildContext(instance);
- var presenter = context.Factory.CreateNodeHierarchy(context.RootNode, new GraphNodePath(context.RootNode));
-
- presenter.Children[1].RemoveItem(instance.List[4], new NodeIndex(4));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(4, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("bbb", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("ccc", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[2].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[3].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[3].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[3].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
- Assert.Equal(instance.List[3], presenter.Children[1].Children[3].Value);
-
- presenter.Children[1].RemoveItem("bbb", new NodeIndex(0));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(3, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("2", presenter.Children[1].Children[2].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("ddd", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[2].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[2].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[2].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
- Assert.Equal(instance.List[2], presenter.Children[1].Children[2].Value);
-
- presenter.Children[1].RemoveItem("ddd", new NodeIndex(1));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(2, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("1", presenter.Children[1].Children[1].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal("eee", presenter.Children[1].Children[1].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[1].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[1].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
- Assert.Equal(instance.List[1], presenter.Children[1].Children[1].Value);
-
- presenter.Children[1].RemoveItem("eee", new NodeIndex(1));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(1, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- Assert.Equal("0", presenter.Children[1].Children[0].Name);
- Assert.Equal("ccc", presenter.Children[1].Children[0].Children[0].Value);
- Assert.Equal(typeof(Types.SimpleType), presenter.Children[1].Children[0].Type);
- Assert.Equal(typeof(string), presenter.Children[1].Children[0].Children[0].Type);
- Assert.Equal(instance.List[0], presenter.Children[1].Children[0].Value);
-
- presenter.Children[1].RemoveItem("ccc", new NodeIndex(0));
- Assert.Equal(typeof(List), presenter.Children[1].Type);
- Assert.Equal(0, presenter.Children[1].Children.Count);
- Assert.Equal(instance.List, presenter.Children[1].Value);
- }
-
- private static TestInstanceContext BuildContext(object instance)
- {
- var context = new TestContainerContext();
- return context.CreateInstanceContext(instance);
- }
+ var context = new TestContainerContext();
+ return context.CreateInstanceContext(instance);
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/CombineMode.cs b/sources/presentation/Stride.Core.Presentation.Quantum/CombineMode.cs
index 9a8ce347cf..c634aeebdb 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/CombineMode.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/CombineMode.cs
@@ -1,26 +1,25 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-namespace Stride.Core.Presentation.Quantum
+namespace Stride.Core.Presentation.Quantum;
+
+///
+/// An enum that describes what to do with a node or a command when combining view models.
+///
+public enum CombineMode
{
///
- /// An enum that describes what to do with a node or a command when combining view models.
+ /// The command or the node should never be combined.
+ ///
+ DoNotCombine,
+ ///
+ /// The command should always be combined, even if some of the combined nodes do not have it.
+ /// The nodes should always be combined, even if some single view models does not have it.
+ ///
+ AlwaysCombine,
+ ///
+ /// The command should be combined only if all combined nodes have it.
+ /// The nodes should be combined only if all single view models have it.
///
- public enum CombineMode
- {
- ///
- /// The command or the node should never be combined.
- ///
- DoNotCombine,
- ///
- /// The command should always be combined, even if some of the combined nodes do not have it.
- /// The nodes should always be combined, even if some single view models does not have it.
- ///
- AlwaysCombine,
- ///
- /// The command should be combined only if all combined nodes have it.
- /// The nodes should be combined only if all single view models have it.
- ///
- CombineOnlyForAll,
- }
+ CombineOnlyForAll,
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/GraphNodeBinding.cs b/sources/presentation/Stride.Core.Presentation.Quantum/GraphNodeBinding.cs
index b0454955f8..47dadca6b6 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/GraphNodeBinding.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/GraphNodeBinding.cs
@@ -1,68 +1,72 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using Stride.Core.Annotations;
+
using Stride.Core.Presentation.Services;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum
+namespace Stride.Core.Presentation.Quantum;
+
+public abstract class GraphNodeBinding : IDisposable
{
- public abstract class GraphNodeBinding : IDisposable
- {
- public delegate void PropertyChangeDelegate(string[] propertyNames);
+ public delegate void PropertyChangeDelegate(string[] propertyNames);
- protected readonly IUndoRedoService ActionService;
- protected readonly string PropertyName;
- protected readonly Func Converter;
+ protected readonly IUndoRedoService ActionService;
+ protected readonly string PropertyName;
+ protected readonly Func Converter;
- private readonly PropertyChangeDelegate propertyChanging;
- private readonly PropertyChangeDelegate propertyChanged;
- private readonly bool notifyChangesOnly;
+ private readonly PropertyChangeDelegate propertyChanging;
+ private readonly PropertyChangeDelegate propertyChanged;
+ private readonly bool notifyChangesOnly;
- internal GraphNodeBinding(string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, [NotNull] Func converter, IUndoRedoService actionService, bool notifyChangesOnly = true)
- {
- PropertyName = propertyName;
- this.propertyChanging = propertyChanging;
- this.propertyChanged = propertyChanged;
- Converter = converter ?? throw new ArgumentNullException(nameof(converter));
- ActionService = actionService;
- this.notifyChangesOnly = notifyChangesOnly;
- }
+ internal GraphNodeBinding(string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, Func converter, IUndoRedoService actionService, bool notifyChangesOnly = true)
+ {
+ PropertyName = propertyName;
+ this.propertyChanging = propertyChanging;
+ this.propertyChanged = propertyChanged;
+ Converter = converter ?? throw new ArgumentNullException(nameof(converter));
+ ActionService = actionService;
+ this.notifyChangesOnly = notifyChangesOnly;
+ }
- ///
- public virtual void Dispose()
- {
- }
+ ///
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ }
- ///
- /// Gets the current value of the graph node.
- ///
- /// The current value of the graph node.
- /// This method can be invoked from a property getter.
- public abstract TContentType GetNodeValue();
+ ///
+ /// Gets the current value of the graph node.
+ ///
+ /// The current value of the graph node.
+ /// This method can be invoked from a property getter.
+ public abstract TContentType GetNodeValue();
- ///
- /// Sets the current value of the graph node.
- ///
- /// The value to set for the graph node content.
- /// This method can be invoked from a property setter.
- /// This method will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.
- public abstract void SetNodeValue(TTargetType value);
+ ///
+ /// Sets the current value of the graph node.
+ ///
+ /// The value to set for the graph node content.
+ /// This method can be invoked from a property setter.
+ /// This method will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.
+ public abstract void SetNodeValue(TTargetType value);
- protected void ValueChanging(object sender, INodeChangeEventArgs e)
+ protected void ValueChanging(object? _, INodeChangeEventArgs e)
+ {
+ if (!notifyChangesOnly || !Equals(e.OldValue, e.NewValue))
{
- if (!notifyChangesOnly || !Equals(e.OldValue, e.NewValue))
- {
- propertyChanging?.Invoke(new[] { PropertyName });
- }
+ propertyChanging?.Invoke([PropertyName]);
}
+ }
- protected void ValueChanged(object sender, INodeChangeEventArgs e)
+ protected void ValueChanged(object? _, INodeChangeEventArgs e)
+ {
+ if (!notifyChangesOnly || !Equals(e.OldValue,e.NewValue))
{
- if (!notifyChangesOnly || !Equals(e.OldValue,e.NewValue))
- {
- propertyChanged?.Invoke(new[] { PropertyName });
- }
+ propertyChanged?.Invoke([PropertyName]);
}
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/GraphViewModelService.cs b/sources/presentation/Stride.Core.Presentation.Quantum/GraphViewModelService.cs
index 3ed89a1487..b5bbb6385e 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/GraphViewModelService.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/GraphViewModelService.cs
@@ -1,35 +1,32 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using System.Collections.Generic;
-using Stride.Core.Annotations;
+
using Stride.Core.Presentation.Quantum.Presenters;
using Stride.Core.Presentation.Quantum.ViewModels;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum
+namespace Stride.Core.Presentation.Quantum;
+
+///
+/// A class that provides various services to objects
+///
+public class GraphViewModelService
{
///
- /// A class that provides various services to objects
+ /// Initializes a new instance of the class.
///
- public class GraphViewModelService
+ public GraphViewModelService(NodeContainer nodeContainer)
{
- ///
- /// Initializes a new instance of the class.
- ///
- public GraphViewModelService([NotNull] NodeContainer nodeContainer)
- {
- if (nodeContainer == null) throw new ArgumentNullException(nameof(nodeContainer));
- NodePresenterFactory = new NodePresenterFactory(nodeContainer.NodeBuilder, AvailableCommands, AvailableUpdaters);
- NodeViewModelFactory = new NodeViewModelFactory();
- }
+ ArgumentNullException.ThrowIfNull(nodeContainer);
+ NodePresenterFactory = new NodePresenterFactory(nodeContainer.NodeBuilder, AvailableCommands, AvailableUpdaters);
+ NodeViewModelFactory = new NodeViewModelFactory();
+ }
- public INodePresenterFactory NodePresenterFactory { get; set; }
+ public INodePresenterFactory NodePresenterFactory { get; set; }
- public NodeViewModelFactory NodeViewModelFactory { get; set; }
+ public NodeViewModelFactory NodeViewModelFactory { get; set; }
- public List AvailableCommands { get; } = new List();
+ public List AvailableCommands { get; } = [];
- public List AvailableUpdaters { get; } = new List();
- }
+ public List AvailableUpdaters { get; } = [];
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/IPropertyProviderViewModel.cs b/sources/presentation/Stride.Core.Presentation.Quantum/IPropertyProviderViewModel.cs
index 373225fca0..ee2bf30264 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/IPropertyProviderViewModel.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/IPropertyProviderViewModel.cs
@@ -1,42 +1,39 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using Stride.Core.Annotations;
-using Stride.Core.Presentation.Quantum.Presenters;
+
using Stride.Core.Presentation.Quantum.ViewModels;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum
+namespace Stride.Core.Presentation.Quantum;
+
+///
+/// An interface representing an view model that can provide properties to build an .
+///
+public interface IPropertyProviderViewModel
{
///
- /// An interface representing an view model that can provide properties to build an .
+ /// Gets whether this view model is currently able to provide properties.
///
- public interface IPropertyProviderViewModel
- {
- ///
- /// Gets whether this view model is currently able to provide properties.
- ///
- bool CanProvidePropertiesViewModel { get; }
+ bool CanProvidePropertiesViewModel { get; }
- ///
- /// Retrieves the root to use to generate properties.
- ///
- /// The root to use to generate properties.
- IObjectNode GetRootNode();
+ ///
+ /// Retrieves the root to use to generate properties.
+ ///
+ /// The root to use to generate properties.
+ IObjectNode GetRootNode();
- ///
- /// Indicates whether the view model of a specific member should be constructed.
- ///
- /// The member to evaluate.
- /// True if the member node should be constructed, False otherwise.
- bool ShouldConstructMember([NotNull] IMemberNode member);
+ ///
+ /// Indicates whether the view model of a specific member should be constructed.
+ ///
+ /// The member to evaluate.
+ /// True if the member node should be constructed, False otherwise.
+ bool ShouldConstructMember(IMemberNode member);
- ///
- /// Indicates whether the view model of a specific item of a collection should be constructed.
- ///
- /// The collection to evaluate.
- /// The index of the item to evaluate.
- /// True if the member node should be constructed, False otherwise.
- bool ShouldConstructItem([NotNull] IObjectNode collection, NodeIndex index);
- }
+ ///
+ /// Indicates whether the view model of a specific item of a collection should be constructed.
+ ///
+ /// The collection to evaluate.
+ /// The index of the item to evaluate.
+ /// True if the member node should be constructed, False otherwise.
+ bool ShouldConstructItem(IObjectNode collection, NodeIndex index);
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/MemberGraphNodeBinding.cs b/sources/presentation/Stride.Core.Presentation.Quantum/MemberGraphNodeBinding.cs
index 54803db228..502ff37c4e 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/MemberGraphNodeBinding.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/MemberGraphNodeBinding.cs
@@ -1,80 +1,80 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using Stride.Core.Annotations;
+
using Stride.Core.Presentation.Services;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum
+namespace Stride.Core.Presentation.Quantum;
+
+///
+/// This class allows to bind a property of a view model to an and properly trigger property change notifications
+/// when the node value is modified.
+///
+/// The type of property bound to the graph node.
+/// The type of content in the graph node.
+public class MemberGraphNodeBinding : GraphNodeBinding
{
- ///
- /// This class allows to bind a property of a view model to an and properly trigger property change notifications
- /// when the node value is modified.
- ///
- /// The type of property bound to the graph node.
- /// The type of content in the graph node.
- public class MemberGraphNodeBinding : GraphNodeBinding
+ protected IMemberNode Node;
+
+ public MemberGraphNodeBinding(IMemberNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, Func converter, IUndoRedoService actionService, bool notifyChangesOnly = true)
+ : base(propertyName, propertyChanging, propertyChanged, converter, actionService, notifyChangesOnly)
{
- protected IMemberNode Node;
+ Node = node;
+ node.ValueChanged += ValueChanged;
+ node.ValueChanging += ValueChanging;
+ }
- public MemberGraphNodeBinding([NotNull] IMemberNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, [NotNull] Func converter, IUndoRedoService actionService, bool notifyChangesOnly = true)
- : base(propertyName, propertyChanging, propertyChanged, converter, actionService, notifyChangesOnly)
- {
- Node = node;
- node.ValueChanged += ValueChanged;
- node.ValueChanging += ValueChanging;
- }
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
- public override void Dispose()
+ if (disposing)
{
- base.Dispose();
Node.ValueChanged -= ValueChanged;
Node.ValueChanging -= ValueChanging;
}
+ }
- public override TContentType GetNodeValue()
- {
- var value = (TContentType)Node.Retrieve();
- return value;
- }
+ public override TContentType GetNodeValue()
+ {
+ var value = (TContentType)Node.Retrieve();
+ return value;
+ }
- public override void SetNodeValue(TTargetType value)
- {
- using (var transaction = ActionService?.CreateTransaction())
- {
- Node.Update(Converter(value));
- ActionService?.SetName(transaction, $"Update property {PropertyName}");
- }
- }
+ public override void SetNodeValue(TTargetType value)
+ {
+ using var transaction = ActionService?.CreateTransaction();
+ Node.Update(Converter(value));
+ ActionService?.SetName(transaction!, $"Update property {PropertyName}");
}
+}
+///
+/// This is a specialization of the class, when the target type is the same that the
+/// content type.
+/// This class allows to bind a property of a view model to a and properly trigger property change notifications
+/// when the node value is modified.
+///
+/// The type of the node content and the property bound to the graph node.
+public class MemberGraphNodeBinding : MemberGraphNodeBinding
+{
///
- /// This is a specialization of the class, when the target type is the same that the
- /// content type.
- /// This class allows to bind a property of a view model to a and properly trigger property change notifications
- /// when the node value is modified.
+ /// Initializes a new instance of the class.
///
- /// The type of the node content and the property bound to the graph node.
- public class MemberGraphNodeBinding : MemberGraphNodeBinding
+ /// The graph node bound to this instance.
+ /// The name of the property of the view model that is bound to this instance.
+ /// The delegate to invoke when the node content is about to change.
+ /// The delegate to invoke when the node content has changed.
+ ///
+ /// If True, delegates will be invoked only if the content of the node has actually changed. Otherwise, they will be invoked every time the node is updated, even if the new value is equal to the previous one.
+ public MemberGraphNodeBinding(IMemberNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, IUndoRedoService actionService, bool notifyChangesOnly = true)
+ : base(node, propertyName, propertyChanging, propertyChanged, x => x, actionService, notifyChangesOnly)
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The graph node bound to this instance.
- /// The name of the property of the view model that is bound to this instance.
- /// The delegate to invoke when the node content is about to change.
- /// The delegate to invoke when the node content has changed.
- ///
- /// If True, delegates will be invoked only if the content of the node has actually changed. Otherwise, they will be invoked every time the node is updated, even if the new value is equal to the previous one.
- public MemberGraphNodeBinding([NotNull] IMemberNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, IUndoRedoService actionService, bool notifyChangesOnly = true)
- : base(node, propertyName, propertyChanging, propertyChanged, x => x, actionService, notifyChangesOnly)
- {
- }
-
- ///
- /// Gets or sets the current node value.
- ///
- /// The setter of this property will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.
- public TContentType Value { get => GetNodeValue(); set => SetNodeValue(value); }
}
+
+ ///
+ /// Gets or sets the current node value.
+ ///
+ /// The setter of this property will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.
+ public TContentType Value { get => GetNodeValue(); set => SetNodeValue(value); }
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/ObjectGraphNodeBinding.cs b/sources/presentation/Stride.Core.Presentation.Quantum/ObjectGraphNodeBinding.cs
index 47f4626370..a76f0a185f 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/ObjectGraphNodeBinding.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/ObjectGraphNodeBinding.cs
@@ -1,80 +1,80 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using Stride.Core.Annotations;
+
using Stride.Core.Presentation.Services;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum
+namespace Stride.Core.Presentation.Quantum;
+
+///
+/// This class allows to bind a property of a view model to an and properly trigger property change notifications
+/// when the node value is modified.
+///
+/// The type of property bound to the graph node.
+/// The type of content in the graph node.
+public class ObjectGraphNodeBinding : GraphNodeBinding
{
- ///
- /// This class allows to bind a property of a view model to an and properly trigger property change notifications
- /// when the node value is modified.
- ///
- /// The type of property bound to the graph node.
- /// The type of content in the graph node.
- public class ObjectGraphNodeBinding : GraphNodeBinding
+ protected IObjectNode Node;
+
+ public ObjectGraphNodeBinding(IObjectNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, Func converter, IUndoRedoService actionService, bool notifyChangesOnly = true)
+ : base(propertyName, propertyChanging, propertyChanged, converter, actionService, notifyChangesOnly)
{
- protected IObjectNode Node;
+ Node = node;
+ node.ItemChanged += ValueChanged;
+ node.ItemChanging += ValueChanging;
+ }
- public ObjectGraphNodeBinding([NotNull] IObjectNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, [NotNull] Func converter, IUndoRedoService actionService, bool notifyChangesOnly = true)
- : base(propertyName, propertyChanging, propertyChanged, converter, actionService, notifyChangesOnly)
- {
- Node = node;
- node.ItemChanged += ValueChanged;
- node.ItemChanging += ValueChanging;
- }
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
- public override void Dispose()
+ if (disposing)
{
- base.Dispose();
Node.ItemChanged -= ValueChanged;
Node.ItemChanging -= ValueChanging;
}
+ }
- public override TContentType GetNodeValue()
- {
- var value = (TContentType)Node.Retrieve();
- return value;
- }
+ public override TContentType GetNodeValue()
+ {
+ var value = (TContentType)Node.Retrieve();
+ return value;
+ }
- public override void SetNodeValue(TTargetType value)
- {
- using (var transaction = ActionService?.CreateTransaction())
- {
- Node.Update(Converter(value), NodeIndex.Empty);
- ActionService?.SetName(transaction, $"Update property {PropertyName}");
- }
- }
+ public override void SetNodeValue(TTargetType value)
+ {
+ using var transaction = ActionService?.CreateTransaction();
+ Node.Update(Converter(value), NodeIndex.Empty);
+ ActionService?.SetName(transaction!, $"Update property {PropertyName}");
}
+}
+///
+/// This is a specialization of the class, when the target type is the same that the
+/// content type.
+/// This class allows to bind a property of a view model to a and properly trigger property change notifications
+/// when the node value is modified.
+///
+/// The type of the node content and the property bound to the graph node.
+public class ObjectGraphNodeBinding : ObjectGraphNodeBinding
+{
///
- /// This is a specialization of the class, when the target type is the same that the
- /// content type.
- /// This class allows to bind a property of a view model to a and properly trigger property change notifications
- /// when the node value is modified.
+ /// Initializes a new instance of the class.
///
- /// The type of the node content and the property bound to the graph node.
- public class ObjectGraphNodeBinding : ObjectGraphNodeBinding
+ /// The graph node bound to this instance.
+ /// The name of the property of the view model that is bound to this instance.
+ /// The delegate to invoke when the node content is about to change.
+ /// The delegate to invoke when the node content has changed.
+ ///
+ /// If True, delegates will be invoked only if the content of the node has actually changed. Otherwise, they will be invoked every time the node is updated, even if the new value is equal to the previous one.
+ public ObjectGraphNodeBinding(IObjectNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, IUndoRedoService actionService, bool notifyChangesOnly = true)
+ : base(node, propertyName, propertyChanging, propertyChanged, x => x, actionService, notifyChangesOnly)
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The graph node bound to this instance.
- /// The name of the property of the view model that is bound to this instance.
- /// The delegate to invoke when the node content is about to change.
- /// The delegate to invoke when the node content has changed.
- ///
- /// If True, delegates will be invoked only if the content of the node has actually changed. Otherwise, they will be invoked every time the node is updated, even if the new value is equal to the previous one.
- public ObjectGraphNodeBinding([NotNull] IObjectNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, IUndoRedoService actionService, bool notifyChangesOnly = true)
- : base(node, propertyName, propertyChanging, propertyChanged, x => x, actionService, notifyChangesOnly)
- {
- }
-
- ///
- /// Gets or sets the current node value.
- ///
- /// The setter of this property will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.
- public TContentType Value { get => GetNodeValue(); set => SetNodeValue(value); }
}
+
+ ///
+ /// Gets or sets the current node value.
+ ///
+ /// The setter of this property will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.
+ public TContentType Value { get => GetNodeValue(); set => SetNodeValue(value); }
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/AnonymousNodePresenterCommand.cs b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/AnonymousNodePresenterCommand.cs
index 714181bfee..69c006ecfe 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/AnonymousNodePresenterCommand.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/AnonymousNodePresenterCommand.cs
@@ -1,38 +1,34 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using System.Threading.Tasks;
-using Stride.Core.Annotations;
-namespace Stride.Core.Presentation.Quantum.Presenters
+namespace Stride.Core.Presentation.Quantum.Presenters;
+
+public class AnonymousNodePresenterCommand : NodePresenterCommandBase
{
- public class AnonymousNodePresenterCommand : NodePresenterCommandBase
- {
- private readonly Func execute;
- private readonly Func canAttach;
+ private readonly Func execute;
+ private readonly Func? canAttach;
- public AnonymousNodePresenterCommand([NotNull] string name, [NotNull] Func execute, [CanBeNull] Func canAttach = null)
- {
- if (name == null) throw new ArgumentNullException(nameof(name));
- if (execute == null) throw new ArgumentNullException(nameof(execute));
- this.execute = execute;
- this.canAttach = canAttach;
- Name = name;
- }
+ public AnonymousNodePresenterCommand(string name, Func execute, Func? canAttach = null)
+ {
+ ArgumentNullException.ThrowIfNull(name);
+ ArgumentNullException.ThrowIfNull(execute);
+ this.execute = execute;
+ this.canAttach = canAttach;
+ Name = name;
+ }
- ///
- public override string Name { get; }
+ ///
+ public override string Name { get; }
- ///
- public override bool CanAttach(INodePresenter nodePresenter)
- {
- return canAttach?.Invoke(nodePresenter) ?? true;
- }
+ ///
+ public override bool CanAttach(INodePresenter nodePresenter)
+ {
+ return canAttach?.Invoke(nodePresenter) ?? true;
+ }
- ///
- public override Task Execute(INodePresenter nodePresenter, object parameter, object preExecuteResult)
- {
- return execute(nodePresenter, parameter);
- }
+ ///
+ public override Task Execute(INodePresenter nodePresenter, object? parameter, object? preExecuteResult)
+ {
+ return execute(nodePresenter, parameter);
}
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/IInitializingNodePresenter.cs b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/IInitializingNodePresenter.cs
index cd5b1ed553..8fb8f673e8 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/IInitializingNodePresenter.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/IInitializingNodePresenter.cs
@@ -1,14 +1,11 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using System.Collections.Generic;
-namespace Stride.Core.Presentation.Quantum.Presenters
+namespace Stride.Core.Presentation.Quantum.Presenters;
+
+public interface IInitializingNodePresenter : INodePresenter
{
- public interface IInitializingNodePresenter : INodePresenter
- {
- void AddChild(IInitializingNodePresenter child);
+ void AddChild(IInitializingNodePresenter child);
- void FinalizeInitialization();
- }
+ void FinalizeInitialization();
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenter.cs b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenter.cs
index 3eba0f766e..2f1a25df4d 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenter.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenter.cs
@@ -1,87 +1,78 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using System.Collections.Generic;
-using Stride.Core;
-using Stride.Core.Annotations;
+
using Stride.Core.Reflection;
using Stride.Core.Quantum;
-namespace Stride.Core.Presentation.Quantum.Presenters
+namespace Stride.Core.Presentation.Quantum.Presenters;
+
+public interface INodePresenter : IDisposable
{
- public interface INodePresenter : IDisposable
- {
- [NotNull]
- INodePresenter this[string childName] { get; }
+ INodePresenter this[string childName] { get; }
- string DisplayName { get; set; }
+ string DisplayName { get; set; }
- string Name { get; }
+ string Name { get; }
- [NotNull]
- INodePresenter Root { get; }
+ INodePresenter Root { get; }
- [CanBeNull]
- INodePresenter Parent { get; }
+ INodePresenter? Parent { get; }
- IReadOnlyList Children { get; }
+ IReadOnlyList Children { get; }
- List Commands { get; }
+ List Commands { get; }
- PropertyContainerClass AttachedProperties { get; }
+ PropertyContainerClass AttachedProperties { get; }
- [NotNull]
- Type Type { get; }
+ Type Type { get; }
- bool IsEnumerable { get; }
+ bool IsEnumerable { get; }
- bool IsReadOnly { get; set; }
+ bool IsReadOnly { get; set; }
- bool IsVisible { get; set; }
+ bool IsVisible { get; set; }
- NodeIndex Index { get; }
+ NodeIndex Index { get; }
- ITypeDescriptor Descriptor { get; }
+ ITypeDescriptor? Descriptor { get; }
- int? Order { get; set; }
+ int? Order { get; set; }
- object Value { get; }
+ object Value { get; }
- string CombineKey { get; set; }
+ string CombineKey { get; set; }
- IPropertyProviderViewModel PropertyProvider { get; }
+ IPropertyProviderViewModel? PropertyProvider { get; }
- INodePresenterFactory Factory { get; }
+ INodePresenterFactory Factory { get; }
- event EventHandler ValueChanging;
+ event EventHandler? ValueChanging;
- event EventHandler ValueChanged;
+ event EventHandler? ValueChanged;
- void UpdateValue(object newValue);
+ void UpdateValue(object newValue);
- void AddItem(object value);
+ void AddItem(object value);
- void AddItem(object value, NodeIndex index);
+ void AddItem(object value, NodeIndex index);
- void RemoveItem(object value, NodeIndex index);
+ void RemoveItem(object value, NodeIndex index);
- // TODO: this should probably be removed, UpdateValue should be called on the corresponding child node presenter itself
+ // TODO: this should probably be removed, UpdateValue should be called on the corresponding child node presenter itself
- NodeAccessor GetNodeAccessor();
+ NodeAccessor GetNodeAccessor();
- ///
- /// Adds a dependency to the given node.
- ///
- /// The node that should be a dependency of this node.
- /// If true, this node will also be refreshed when one of the child node of the dependency node changes.
- /// A node that is a dependency to this node will trigger a refresh of this node each time its value is modified (or the value of one of its parent).
- void AddDependency(INodePresenter node, bool refreshOnNestedNodeChanges);
+ ///
+ /// Adds a dependency to the given node.
+ ///
+ /// The node that should be a dependency of this node.
+ /// If true, this node will also be refreshed when one of the child node of the dependency node changes.
+ /// A node that is a dependency to this node will trigger a refresh of this node each time its value is modified (or the value of one of its parent).
+ void AddDependency(INodePresenter node, bool refreshOnNestedNodeChanges);
- void ChangeParent([NotNull] INodePresenter newParent);
+ void ChangeParent(INodePresenter newParent);
- void Rename(string newName, bool overwriteCombineKey = true);
+ void Rename(string newName, bool overwriteCombineKey = true);
- [CanBeNull]
- INodePresenter TryGetChild(string childName);
- }
+ INodePresenter? TryGetChild(string childName);
}
diff --git a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenterCommand.cs b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenterCommand.cs
index 530b2af26b..44f19792c6 100644
--- a/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenterCommand.cs
+++ b/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/INodePresenterCommand.cs
@@ -1,27 +1,21 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Stride.Core.Annotations;
-namespace Stride.Core.Presentation.Quantum.Presenters
+namespace Stride.Core.Presentation.Quantum.Presenters;
+
+public interface INodePresenterCommand
{
- public interface INodePresenterCommand
- {
- [NotNull]
- string Name { get; }
+ string Name { get; }
- CombineMode CombineMode { get; }
+ CombineMode CombineMode { get; }
- bool CanAttach([NotNull] INodePresenter nodePresenter);
+ bool CanAttach(INodePresenter nodePresenter);
- bool CanExecute([NotNull] IReadOnlyCollection nodePresenters, object parameter);
+ bool CanExecute(IReadOnlyCollection nodePresenters, object? parameter);
- Task