mirror of
https://github.com/chylex/.NET-Community-Toolkit.git
synced 2025-08-16 23:31:47 +02:00
.github
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
CommunityToolkit.Mvvm
CommunityToolkit.Mvvm.SourceGenerators
build
tests
CommunityToolkit.Common.UnitTests
CommunityToolkit.Diagnostics.UnitTests
CommunityToolkit.HighPerformance.UnitTests
Buffers
Enumerables
Extensions
Helpers
Memory
Streams
CommunityToolkit.HighPerformance.UnitTests.csproj
Test_Box{T}.cs
Test_NullableReadOnlyRef{T}.cs
Test_NullableRef{T}.cs
Test_ReadOnlyRef{T}.cs
Test_Ref{T}.cs
CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests
CommunityToolkit.Mvvm.ExternalAssembly
CommunityToolkit.Mvvm.Internals.UnitTests
CommunityToolkit.Mvvm.SourceGenerators.UnitTests
CommunityToolkit.Mvvm.UnitTests
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
.runsettings
CODE_OF_CONDUCT.md
Contributing.md
Directory.Build.props
Directory.Build.targets
License.md
README.md
ThirdPartyNotices.txt
azure-pipelines.yml
dotnet Community Toolkit.sln
toolkit.snk
version.json
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Runtime.CompilerServices;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace CommunityToolkit.HighPerformance.UnitTests;
|
|
|
|
[TestClass]
|
|
public class Test_ReadOnlyRefOfT
|
|
{
|
|
[TestMethod]
|
|
#if NETFRAMEWORK
|
|
public void Test_RefOfT_CreateRefOfT()
|
|
{
|
|
ReadOnlyFieldOwner model = new();
|
|
ReadOnlyRef<int> reference = new(model, model.Value);
|
|
|
|
Assert.IsTrue(Unsafe.AreSame(ref Unsafe.AsRef(model.Value), ref Unsafe.AsRef(reference.Value)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// A dummy model that owns an <see cref="int"/> field.
|
|
/// </summary>
|
|
private sealed class ReadOnlyFieldOwner
|
|
{
|
|
public readonly int Value = 1;
|
|
}
|
|
#else
|
|
public void Test_RefOfT_CreateRefOfT()
|
|
{
|
|
int value = 1;
|
|
ReadOnlyRef<int> reference = new(value);
|
|
|
|
Assert.IsTrue(Unsafe.AreSame(ref value, ref Unsafe.AsRef(reference.Value)));
|
|
}
|
|
#endif
|
|
}
|