Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions sources/core/Stride.Core.Design/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections;
using System.Runtime.CompilerServices;
using Stride.Core.Annotations;

namespace Stride.Core.Extensions;

Expand All @@ -17,8 +16,7 @@ public static class ObjectExtensions
/// </summary>
/// <param name="obj">The object.</param>
/// <returns>The return value of <see cref="object.ToString"/>, or "(null)" if <see ref="obj"/> is null, or (ExceptionInToString)" if <see cref="object.ToString"/> thrown an exception.</returns>
[NotNull]
public static string ToStringSafe([CanBeNull] this object obj)
public static string ToStringSafe(this object? obj)
{
try
{
Expand Down Expand Up @@ -54,8 +52,16 @@ public static string ToStringSafe([CanBeNull] this object obj)
if (obj is IEnumerable<T?> enumerableT)
return enumerableT;

var enumerable = obj as IEnumerable;
return enumerable?.Cast<T>() ?? Yield((T?)obj);
if (obj is IEnumerable enumerable)
return enumerable.OfType<T>();

if (obj is null)
return Yield((T?)obj);

if (obj is T t)
return Yield(t);

return [];
}

/// <summary>
Expand All @@ -67,7 +73,6 @@ public static string ToStringSafe([CanBeNull] this object obj)
/// <param name="argumentName">The name of the argument, in case an <see cref="ArgumentNullException"/> must be thrown.</param>
/// <returns>The given object.</returns>
/// <remarks>This method can be used to test for null argument when forwarding members of the object to the <c>base</c> or <c>this</c> constructor.</remarks>
[NotNull]
public static T SafeArgument<T>(this T obj, [CallerArgumentExpression(nameof(obj))] string argumentName = "") where T : class
{
#if NET6_0_OR_GREATER
Expand Down
3 changes: 3 additions & 0 deletions sources/core/Stride.Core.Reflection/ITypeDescriptorFactory.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
Expand All @@ -19,5 +21,6 @@ public interface ITypeDescriptorFactory
/// </summary>
/// <param name="type">The type.</param>
/// <returns>ITypeDescriptor.</returns>
[return: NotNullIfNotNull(nameof(type))]
ITypeDescriptor? Find(Type? type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ public interface IMemberDescriptor
/// </summary>
/// <param name="thisObject">The this object.</param>
/// <param name="value">The value.</param>
void Set(object thisObject, object value);
void Set(object thisObject, object? value);
}
2 changes: 2 additions & 0 deletions sources/core/Stride.Core.Reflection/TypeDescriptorFactory.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ public static bool IsCollection(Type type)
/// </summary>
/// <param name="collection">The collection.</param>
/// <returns>The number of elements of a collection, -1 if it cannot determine the number of elements.</returns>
public abstract int GetCollectionCount(object collection);
public abstract int GetCollectionCount(object? collection);
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public override void RemoveAt(object list, int index)
/// </summary>
/// <param name="list">The list.</param>
/// <returns>The number of elements of a list, -1 if it cannot determine the number of elements.</returns>
public override int GetCollectionCount(object list)
public override int GetCollectionCount(object? list)
{
return list == null || getListCountMethod == null ? -1 : getListCountMethod(list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public override bool IsReadOnly(object collection)
/// </summary>
/// <param name="collection">The collection.</param>
/// <returns>The number of elements of a collection, -1 if it cannot determine the number of elements.</returns>
public override int GetCollectionCount(object collection)
public override int GetCollectionCount(object? collection)
{
return collection == null || getCollectionCountMethod == null ? -1 : getCollectionCountMethod(collection);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -132,7 +133,7 @@ public bool Contains(object set, object? value)
/// </summary>
/// <param name="set">The set.</param>
/// <returns>The number of elements of a set, -1 if it cannot determine the number of elements.</returns>
public override int GetCollectionCount(object set)
public override int GetCollectionCount([NotNull] object? set)
{
ArgumentNullException.ThrowIfNull(set);
return countMethod.Invoke(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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])!;
}
}
Original file line number Diff line number Diff line change
@@ -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<string> List { get; set; } = new List<string>();
}
public class ClassWithCollection
{
[Display(1)]
public required string String { get; set; }
[Display(2)]
public List<string> List { get; set; } = [];
}

public class ClassWithRefCollection
{
[Display(1)]
public string String { get; set; }
[Display(2)]
public List<SimpleType> List { get; set; } = new List<SimpleType>();
}
public class ClassWithRefCollection
{
[Display(1)]
public required string String { get; set; }
[Display(2)]
public List<SimpleType> List { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading