Merge pull request #1654 from Jklawreszuk/core-obsoletes

[Core] Remove some obsolete code
This commit is contained in:
Marian Dziubiak 2023-05-25 13:09:28 +01:00 коммит произвёл GitHub
Родитель 77d5ea6067 c4fdbd0638
Коммит 8fe8da27ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
33 изменённых файлов: 105 добавлений и 1310 удалений

Просмотреть файл

@ -313,7 +313,7 @@ namespace Stride.Core.Assets.CompilerApp
if (header.OffsetToReferences != -1)
{
// Seek to where references are stored and deserialize them
streamReader.NativeStream.Seek(header.OffsetToReferences, SeekOrigin.Begin);
streamReader.UnderlyingStream.Seek(header.OffsetToReferences, SeekOrigin.Begin);
List<ChunkReference> chunkReferences = null;
streamReader.Serialize(ref chunkReferences, ArchiveMode.Deserialize);

Просмотреть файл

@ -147,11 +147,11 @@ namespace Stride.Core.BuildEngine
var hash = prepareContext.ComputeInputHash(inputFile.Type, inputFile.Path);
if (hash == ObjectId.Empty)
{
writer.NativeStream.WriteByte(0);
writer.UnderlyingStream.WriteByte(0);
}
else
{
writer.NativeStream.Write((byte[])hash, 0, ObjectId.HashSize);
writer.UnderlyingStream.Write((byte[])hash, 0, ObjectId.HashSize);
}
}
}

Просмотреть файл

@ -1,10 +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;
using Xunit;
using Stride.Core.Reflection;
using System.Collections.Generic;
namespace Stride.Core.Design.Tests
{
@ -25,32 +23,5 @@ namespace Stride.Core.Design.Tests
var shadowObject2 = ShadowObject.GetOrCreate(obj);
Assert.Equal(shadowObject, shadowObject2);
}
// IdentifierHelper is now obsolete
//[Fact]
//public void TestIdentifierHelper()
//{
// // Has IdentifierHelper is using ShadowObject, we will test it here
// ShadowObject.Enable = true;
// var obj = new object();
// var id = IdentifiableHelper.GetId(obj);
// Assert.NotEqual(Guid.Empty, id);
// var id1 = IdentifiableHelper.GetId(obj);
// Assert.Equal(id, id1);
// // We should not get an id for a collection
// var idCollection = IdentifiableHelper.GetId(new List<object>());
// Assert.Equal(Guid.Empty, idCollection);
// // We should not get an id for a dictionary
// var idDict = IdentifiableHelper.GetId(new MyDictionary());
// Assert.Equal(Guid.Empty, idDict);
//}
private class MyDictionary : Dictionary<object, object>
{
}
}
}

Просмотреть файл

@ -1007,35 +1007,6 @@ namespace Stride.Core.Mathematics
return result;
}
/// <summary>
/// Determines the product of two matrices.
/// Variables passed as <paramref name="left"/> or <paramref name="right"/> must not be used as the out parameter
/// <paramref name="result"/>, because <paramref name="result"/> is calculated in-place.
/// </summary>
/// <param name="left">The first matrix to multiply.</param>
/// <param name="right">The second matrix to multiply.</param>
/// <param name="result">The product of the two matrices.</param>
[Obsolete($"Use {nameof(Multiply)} instead, this signature will be removed")]
public static void MultiplyTo(ref Matrix left, ref Matrix right, out Matrix result)
{
result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41);
result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41);
result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41);
result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41);
result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42);
result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42);
result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42);
result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42);
result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43);
result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43);
result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43);
result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43);
result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44);
result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44);
result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44);
result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44);
}
/// <summary>
/// Determines the product of two matrices.
/// Variables passed as <paramref name="left"/> or <paramref name="right"/> must not be used as the out parameter
@ -1068,20 +1039,6 @@ namespace Stride.Core.Mathematics
UnsafeRefAsDotNet(in result) = LayoutIsRowMajor ? l * r : r * l;
}
/// <summary>
/// Determines the product of two matrices.
/// Variables passed as <paramref name="left"/> or <paramref name="right"/> must not be used as the out parameter
/// <paramref name="result"/>, because <paramref name="result"/> is calculated in-place.
/// </summary>
/// <param name="left">The first matrix to multiply.</param>
/// <param name="right">The second matrix to multiply.</param>
/// <param name="result">The product of the two matrices.</param>
[Obsolete($"Use {nameof(Multiply)} instead")]
public static void MultiplyRef(ref Matrix left, ref Matrix right, ref Matrix result)
{
Multiply(ref left, ref right, out result);
}
/// <summary>
/// Determines the product of two matrices, equivalent to the '*' operator.
/// </summary>

Просмотреть файл

@ -24,7 +24,28 @@ namespace Stride.Core.Reflection
/// <returns><c>true</c> if the specified type is collection; otherwise, <c>false</c>.</returns>
public static bool IsCollection(Type type)
{
return TypeHelper.IsCollection(type);
if (type == null) throw new ArgumentNullException(nameof(type));
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsArray)
{
return false;
}
if (typeof(IList).GetTypeInfo().IsAssignableFrom(typeInfo))
{
return true;
}
foreach (var iType in typeInfo.ImplementedInterfaces)
{
var iTypeInfo = iType.GetTypeInfo();
if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(ICollection<>))
{
return true;
}
}
return false;
}
/// <summary>

Просмотреть файл

@ -272,7 +272,23 @@ namespace Stride.Core.Reflection
/// <returns><c>true</c> if the specified type is dictionary; otherwise, <c>false</c>.</returns>
public static bool IsDictionary(Type type)
{
return TypeHelper.IsDictionary(type);
if (type == null) throw new ArgumentNullException(nameof(type));
var typeInfo = type.GetTypeInfo();
if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(typeInfo))
{
return true;
}
foreach (var iType in typeInfo.ImplementedInterfaces)
{
var iTypeInfo = iType.GetTypeInfo();
if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(IDictionary<,>))
{
return true;
}
}
return false;
}
public static IEnumerable<KeyValuePair<object, object>> GetGenericEnumerable<TKey, TValue>(IDictionary<TKey, TValue> dictionary)

Просмотреть файл

@ -50,7 +50,7 @@ namespace Stride.Core.Serialization.Contents
if (magic != Magic)
{
// Rewind
stream.NativeStream.Seek(-4, SeekOrigin.Current);
stream.UnderlyingStream.Seek(-4, SeekOrigin.Current);
return null;
}

Просмотреть файл

@ -518,9 +518,9 @@ namespace Stride.Core.Serialization.Contents
if (chunkHeader != null && chunkHeader.OffsetToReferences != -1)
{
// Seek to where references are stored and deserialize them
streamReader.NativeStream.Seek(chunkHeader.OffsetToReferences, SeekOrigin.Begin);
streamReader.UnderlyingStream.Seek(chunkHeader.OffsetToReferences, SeekOrigin.Begin);
contentSerializerContext.SerializeReferences(streamReader);
streamReader.NativeStream.Seek(chunkHeader.OffsetToObject, SeekOrigin.Begin);
streamReader.UnderlyingStream.Seek(chunkHeader.OffsetToObject, SeekOrigin.Begin);
}
if (reference == null)
@ -631,7 +631,7 @@ namespace Stride.Core.Serialization.Contents
{
header = new ChunkHeader { Type = serializer.SerializationType.AssemblyQualifiedName };
header.Write(streamWriter);
header.OffsetToObject = (int)streamWriter.NativeStream.Position;
header.OffsetToObject = (int)streamWriter.UnderlyingStream.Position;
}
contentSerializerContext.SerializeContent(streamWriter, serializer, obj);
@ -639,7 +639,7 @@ namespace Stride.Core.Serialization.Contents
// Write references and updated header
if (header != null)
{
header.OffsetToReferences = (int)streamWriter.NativeStream.Position;
header.OffsetToReferences = (int)streamWriter.UnderlyingStream.Position;
contentSerializerContext.SerializeReferences(streamWriter);
// Move back to the pre-allocated header position in the steam

Просмотреть файл

@ -47,42 +47,6 @@ namespace Stride.Core.Annotations
LargeStep = largeStep;
}
/// <summary>
/// Initializes a new instance of the <see cref="DataMemberRangeAttribute" /> class.
/// </summary>
/// <param name="minimum">The minimum.</param>
/// <param name="maximum">The maximum.</param>
[Obsolete("This method will be removed in a future release. Use DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces) instead")]
public DataMemberRangeAttribute(double minimum, double maximum)
: this(minimum, maximum, 1, 2, 3)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DataMemberRangeAttribute" /> class.
/// </summary>
/// <param name="minimum">The minimum.</param>
/// <param name="maximum">The maximum.</param>
/// <param name="decimalPlaces">The decimal places</param>
[Obsolete("This method will be removed in a future release. Use DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces) instead")]
public DataMemberRangeAttribute(double minimum, double maximum, int decimalPlaces)
: this(minimum, maximum, 1, 2, decimalPlaces)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DataMemberRangeAttribute" /> class.
/// </summary>
/// <param name="minimum">The minimum.</param>
/// <param name="maximum">The maximum.</param>
/// <param name="smallStep">The minimum step used to go from minimum to maximum.</param>
/// <param name="largeStep">The maximum step.</param>
[Obsolete("This method will be removed in a future release. Use DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces) instead")]
public DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep)
: this(minimum, maximum, smallStep, largeStep, 3)
{
}
/// <summary>
/// Gets the minimum inclusive.
/// </summary>

Просмотреть файл

@ -1,19 +0,0 @@
// 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;
namespace Stride.Core.Collections
{
/// <summary>
/// Array helper for a particular type, useful to get an empty array.
/// </summary>
/// <typeparam name="T">Type of the array element</typeparam>
[Obsolete("This method is deprecated and may be removed in future versions. Please use Array.Empty<T>() instead. See https://docs.microsoft.com/en-us/dotnet/api/system.array.empty?view=net-5.0 for details.")]
public struct ArrayHelper<T>
{
/// <summary>
/// An empty array of the specified <see cref="T"/> element type.
/// </summary>
public static readonly T[] Empty = Array.Empty<T>();
}
}

Просмотреть файл

@ -1,15 +0,0 @@
// 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;
namespace Stride.Core.IL
{
/// <summary>
/// Using this optimization attribute will prevent local variables in this method to be zero-ed in the prologue (if the runtime supports it).
/// </summary>
[AttributeUsage(AttributeTargets.Method), Obsolete("Use System.Runtime.CompilerServices.SkipLocalsInitAttribute")]
public class RemoveInitLocalsAttribute : Attribute
{
}
}

Просмотреть файл

@ -1,174 +0,0 @@
// 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.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
namespace Stride.Core.IO
{
/// <summary>
/// A <see cref="MemoryStream"/> over a native memory region.
/// </summary>
[Obsolete("Consider using MemoryStream or UnmanagedMemoryStream.")]
public unsafe class NativeMemoryStream : Stream
{
private readonly byte* dataStart;
private readonly byte* dataEnd;
private byte* dataCurrent;
/// <summary>
/// Initializes a new instance of the <see cref="NativeMemoryStream"/> class.
/// </summary>
/// <param name="data">The native data pointer.</param>
/// <param name="length">The data length.</param>
[Obsolete("Consider using MemoryStream or UnmanagedMemoryStream.")]
public NativeMemoryStream(IntPtr data, long length)
: this((byte*)data, length)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="NativeMemoryStream"/> class.
/// </summary>
/// <param name="data">The native data pointer.</param>
/// <param name="length">The data length.</param>
[Obsolete("Consider using MemoryStream or UnmanagedMemoryStream.")]
public NativeMemoryStream(byte* data, long length)
{
this.dataStart = data;
this.dataCurrent = data;
this.dataEnd = data + length;
}
/// <inheritdoc/>
public override void Flush()
{
}
/// <inheritdoc/>
public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
dataCurrent = dataStart + offset;
break;
case SeekOrigin.Current:
dataCurrent += offset;
break;
case SeekOrigin.End:
dataCurrent = dataEnd + offset;
break;
default:
throw new ArgumentOutOfRangeException(nameof(origin));
}
return dataCurrent - dataStart;
}
/// <inheritdoc/>
public override void SetLength(long value)
{
throw new NotSupportedException("Length can't be changed.");
}
/// <inheritdoc/>
public override int Read(Span<byte> buffer)
{
Debug.Assert(dataEnd >= dataCurrent);
var read = (nint)(dataEnd - dataCurrent);
if (read > buffer.Length) read = buffer.Length;
var src = new Span<byte>(dataCurrent, (int)read);
src.CopyTo(buffer);
dataCurrent += read;
return (int)read;
}
/// <inheritdoc/>
public override unsafe int Read(byte[] buffer, int offset, int count)
{
Debug.Assert(
(offset | count) >= 0 &&
(uint)offset + (uint)count <= (uint)buffer.Length);
var bytesLeft = (int)(dataEnd - dataCurrent);
if (count > bytesLeft)
count = bytesLeft;
fixed (byte* pinned = &buffer[0])
Unsafe.CopyBlockUnaligned(pinned + offset, dataCurrent, (uint)count);
dataCurrent += count;
return count;
}
/// <inheritdoc/>
/// <exception cref="IOException">The remaining capacity in the stream
/// is not large enough to write the specified <paramref name="buffer"/>.</exception>
public override void Write(ReadOnlySpan<byte> buffer)
{
Debug.Assert(dataEnd >= dataCurrent);
var written = (nint)(dataEnd - dataCurrent);
if (written < buffer.Length)
throw new IOException("Can't write beyond end of stream.");
else
written = buffer.Length;
var dst = new Span<byte>(dataCurrent, (int)written);
buffer.CopyTo(dst);
dataCurrent += written;
}
/// <inheritdoc/>
/// <exception cref="IOException">The remaining capacity in the stream
/// is not large enough to write the specified <paramref name="buffer"/>.</exception>
public override void Write(byte[] buffer, int offset, int count)
{
Debug.Assert(
(offset | count) >= 0 &&
(uint)offset + (uint)count <= (uint)buffer.Length);
var bytesLeft = (int)(dataEnd - dataCurrent);
if (count > bytesLeft)
throw new IOException("Can't write beyond end of stream.");
fixed (byte* pinned = &buffer[0])
Unsafe.CopyBlockUnaligned(dataCurrent, pinned + offset, (uint)count);
dataCurrent += count;
}
/// <inheritdoc/>
public override int ReadByte()
{
if (dataCurrent >= dataEnd)
return -1;
return *dataCurrent++;
}
/// <inheritdoc/>
/// <exception cref="IOException">The remaining capacity in the stream
/// is not large enough to write the specified <paramref name="buffer"/>.</exception>
public override void WriteByte(byte value)
{
if (dataCurrent >= dataEnd)
throw new IOException("Cannot write beyond end of stream.");
*dataCurrent++ = value;
}
/// <inheritdoc/>
public override bool CanRead => true;
/// <inheritdoc/>
public override bool CanSeek => true;
/// <inheritdoc/>
public override bool CanWrite => true;
/// <inheritdoc/>
public override long Length => dataEnd - dataStart;
/// <inheritdoc/>
public override long Position
{
get => dataCurrent - dataStart;
set => dataCurrent = dataStart + value;
}
}
}

Просмотреть файл

@ -108,68 +108,5 @@ namespace Stride.Core.IO
Write(temporaryBuffer, 0, sizeof(ulong));
}
/// <summary>
/// Reads a block of bytes from the stream and writes the data in a given buffer.
/// </summary>
/// <param name="buffer">When this method returns, contains the specified buffer with the values between 0 and (count - 1) replaced by the bytes read from the current source. </param>
/// <param name="count">The maximum number of bytes to read. </param>
/// <exception cref="ArgumentNullException">array is null. </exception>
/// <returns>The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.</returns>
[Obsolete("Use Stream.Read(Span<byte>).")]
public virtual unsafe int Read(nint buffer, int count)
{
var temporaryBuffer = nativeStreamBuffer;
if (temporaryBuffer == null)
temporaryBuffer = nativeStreamBuffer = new byte[NativeStreamBufferSize];
var readSize = 0;
fixed (byte* temporaryBufferStart = temporaryBuffer) {
for (var offset = 0; offset < count; offset += NativeStreamBufferSize, buffer += NativeStreamBufferSize)
{
// Compute missing bytes in this block
var blockSize = count - offset;
if (blockSize > NativeStreamBufferSize)
blockSize = NativeStreamBufferSize;
var currentReadSize = Read(temporaryBuffer, 0, blockSize);
readSize += currentReadSize;
Unsafe.CopyBlockUnaligned((void*)buffer, temporaryBufferStart, (uint)currentReadSize);
// Reached end of stream?
if (currentReadSize < blockSize)
break;
}
}
return readSize;
}
/// <summary>
/// Writes a block of bytes to this stream using data from a buffer.
/// </summary>
/// <param name="buffer">The buffer containing data to write to the stream.</param>
/// <param name="count">The number of bytes to be written to the current stream. </param>
[Obsolete("Use Stream.Write(ReadOnlySpan<byte>).")]
public virtual unsafe void Write(nint buffer, int count)
{
var temporaryBuffer = nativeStreamBuffer;
if (temporaryBuffer == null)
temporaryBuffer = nativeStreamBuffer = new byte[NativeStreamBufferSize];
fixed (byte* temporaryBufferStart = temporaryBuffer) {
for (var offset = 0; offset < count; offset += NativeStreamBufferSize, buffer += NativeStreamBufferSize)
{
// Compute missing bytes in this block
var blockSize = count - offset;
if (blockSize > NativeStreamBufferSize)
blockSize = NativeStreamBufferSize;
Unsafe.CopyBlockUnaligned(temporaryBufferStart, (void*)buffer, (uint)blockSize);
Write(temporaryBuffer, 0, blockSize);
}
}
}
}
}

Просмотреть файл

@ -1,33 +0,0 @@
// 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.IO;
using Stride.Core.Annotations;
namespace Stride.Core.IO
{
/// <summary>
/// Extension methods concerning <see cref="NativeStream"/>.
/// </summary>
[Obsolete]
public static class NativeStreamExtensions
{
/// <summary>
/// Converts a <see cref="Stream"/> to a <see cref="NativeStream"/>.
/// </summary>
/// <remarks>
/// If <see cref="stream"/> is already a <see cref="NativeStream"/>, it will be returned as is.
/// Otherwise, a <see cref="NativeStreamWrapper"/> around it will be created.
/// </remarks>
/// <param name="stream">The stream.</param>
/// <returns></returns>
[NotNull, Obsolete]
public static NativeStream ToNativeStream(this Stream stream)
{
if (stream is not NativeStream nativeStream)
nativeStream = new NativeStreamWrapper(stream);
return nativeStream;
}
}
}

Просмотреть файл

@ -1,152 +0,0 @@
// 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.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Stride.Core.IO
{
[Obsolete]
public class NativeStreamWrapper : NativeStream
{
private readonly Stream stream;
public NativeStreamWrapper(Stream stream)
{
this.stream = stream;
}
/// <inheritdoc/>
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
return stream.CopyToAsync(destination, bufferSize, cancellationToken);
}
/// <inheritdoc/>
public override void Flush()
{
stream.Flush();
}
/// <inheritdoc/>
public override Task FlushAsync(CancellationToken cancellationToken)
{
return stream.FlushAsync(cancellationToken);
}
/// <inheritdoc/>
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
=> stream.ReadAsync(buffer, cancellationToken);
/// <inheritdoc/>
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return stream.ReadAsync(buffer, offset, count, cancellationToken);
}
/// <inheritdoc/>
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
=> stream.WriteAsync(buffer, cancellationToken);
/// <inheritdoc/>
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return stream.WriteAsync(buffer, offset, count, cancellationToken);
}
/// <inheritdoc/>
public override long Seek(long offset, SeekOrigin origin)
{
return stream.Seek(offset, origin);
}
/// <inheritdoc/>
public override void SetLength(long value)
{
stream.SetLength(value);
}
/// <inheritdoc/>
public override int Read(Span<byte> buffer) => stream.Read(buffer);
/// <inheritdoc/>
public override int Read(byte[] buffer, int offset, int count)
{
return stream.Read(buffer, offset, count);
}
/// <inheritdoc/>
public override int ReadByte()
{
return stream.ReadByte();
}
/// <inheritdoc/>
public override void Write(ReadOnlySpan<byte> buffer) => stream.Write(buffer);
/// <inheritdoc/>
public override void Write(byte[] buffer, int offset, int count)
{
stream.Write(buffer, offset, count);
}
/// <inheritdoc/>
public override void WriteByte(byte value)
{
stream.WriteByte(value);
}
/// <inheritdoc/>
public override bool CanRead
{
get { return stream.CanRead; }
}
/// <inheritdoc/>
public override bool CanSeek
{
get { return stream.CanSeek; }
}
/// <inheritdoc/>
public override bool CanTimeout
{
get { return stream.CanTimeout; }
}
/// <inheritdoc/>
public override bool CanWrite
{
get { return stream.CanWrite; }
}
/// <inheritdoc/>
public override long Length
{
get { return stream.Length; }
}
/// <inheritdoc/>
public override long Position
{
get { return stream.Position; }
set { stream.Position = value; }
}
/// <inheritdoc/>
public override int ReadTimeout
{
get { return stream.ReadTimeout; }
set { stream.ReadTimeout = value; }
}
/// <inheritdoc/>
public override int WriteTimeout
{
get { return stream.WriteTimeout; }
set { stream.WriteTimeout = value; }
}
}
}

Просмотреть файл

@ -1,25 +0,0 @@
// 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;
namespace Stride.Core
{
/// <summary>
/// This class is an implementation of the <see cref="IDisposable"/> interface that does nothing when disposed.
/// </summary>
[Obsolete] // not used, shouldn't be public
public class NullDisposable : IDisposable
{
/// <summary>
/// A static instance of the <see cref="NullDisposable"/> class.
/// </summary>
public static readonly NullDisposable Instance = new();
/// <summary>
/// Implementation of the <see cref="IDisposable.Dispose"/> method. This method does nothing.
/// </summary>
public void Dispose()
{
}
}
}

Просмотреть файл

@ -1,65 +0,0 @@
// 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;
using System.Collections.Generic;
using System.Reflection;
using Stride.Core.Annotations;
namespace Stride.Core.Reflection
{
// TODO: these methods should be compilant with collection/dictionary descriptors. Since they're used only for design-time, they should be removed from here anyway
[Obsolete("This class will be removed in a future version")]
public static class TypeHelper
{
[Obsolete("This method will be removed in a future version")]
public static bool IsCollection([NotNull] this Type type)
{
if (type == null) throw new ArgumentNullException(nameof(type));
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsArray)
{
return false;
}
if (typeof(IList).GetTypeInfo().IsAssignableFrom(typeInfo))
{
return true;
}
foreach (var iType in typeInfo.ImplementedInterfaces)
{
var iTypeInfo = iType.GetTypeInfo();
if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(ICollection<>))
{
return true;
}
}
return false;
}
[Obsolete("This method will be removed in a future version")]
public static bool IsDictionary([NotNull] this Type type)
{
if (type == null) throw new ArgumentNullException(nameof(type));
var typeInfo = type.GetTypeInfo();
if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(typeInfo))
{
return true;
}
foreach (var iType in typeInfo.ImplementedInterfaces)
{
var iTypeInfo = iType.GetTypeInfo();
if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(IDictionary<,>))
{
return true;
}
}
return false;
}
}
}

Просмотреть файл

@ -1,57 +0,0 @@
// 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.IO;
using Stride.Core.Annotations;
namespace Stride.Core.Serialization
{
/// <summary>
/// Binary serialization method helpers to easily read/write data from a stream.
/// </summary>
/// <remarks>
/// This class is a simple front end to <see cref="BinarySerializationReader"/> and <see cref="BinarySerializationWriter"/>.
/// </remarks>
[Obsolete] // inefficient, not recommended
public class BinarySerialization
{
/// <summary>
/// Reads an object instance from the specified stream.
/// </summary>
/// <typeparam name="T">Type of the object to read</typeparam>
/// <param name="stream">The stream to read the object instance.</param>
/// <returns>An object instance of type T.</returns>
[Obsolete("Use BinarySerializationReader.Read<T> instead.")]
public static T Read<T>([NotNull] Stream stream)
{
var reader = new BinarySerializationReader(stream);
return reader.Read<T>();
}
/// <summary>
/// Reads an object instance from the specified byte buffer.
/// </summary>
/// <typeparam name="T">Type of the object to read</typeparam>
/// <param name="buffer">The byte buffer to read the object instance.</param>
/// <returns>An object instance of type T.</returns>
[Obsolete("Use BinarySerializationReader.Read<T> with a MemoryStream instead.")]
public static T Read<T>([NotNull] byte[] buffer)
{
var reader = new BinarySerializationReader(new MemoryStream(buffer));
return reader.Read<T>();
}
/// <summary>
/// Writes an object instance to the specified stream.
/// </summary>
/// <typeparam name="T">Type of the object to write</typeparam>
/// <param name="stream">The stream to write the object instance to.</param>
/// <param name="value">The value to write.</param>
[Obsolete("Use BinarySerializationWriter.Write<T> instead.")]
public static void Write<T>([NotNull] Stream stream, T value)
{
var writer = new BinarySerializationWriter(stream);
writer.Write(value);
}
}
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace Stride.Core.Serialization
public BinarySerializationReader([NotNull] Stream inputStream)
{
Reader = new BinaryReader(inputStream);
NativeStream = inputStream;
UnderlyingStream = inputStream;
}
private BinaryReader Reader { get; }
@ -27,7 +27,7 @@ namespace Stride.Core.Serialization
/// <inheritdoc />
public override void Serialize(ref bool value)
{
var result = NativeStream.ReadByte();
var result = UnderlyingStream.ReadByte();
if (result == -1)
throw new EndOfStreamException();
value = result != 0;
@ -38,50 +38,50 @@ namespace Stride.Core.Serialization
public override unsafe void Serialize(ref float value)
{
fixed (float* valuePtr = &value)
*((uint*)valuePtr) = NativeStream.ReadUInt32();
*((uint*)valuePtr) = UnderlyingStream.ReadUInt32();
}
/// <inheritdoc />
public override unsafe void Serialize(ref double value)
{
fixed (double* valuePtr = &value)
*((ulong*)valuePtr) = NativeStream.ReadUInt64();
*((ulong*)valuePtr) = UnderlyingStream.ReadUInt64();
}
/// <inheritdoc />
public override void Serialize(ref short value)
{
value = (short)NativeStream.ReadUInt16();
value = (short)UnderlyingStream.ReadUInt16();
}
/// <inheritdoc />
public override void Serialize(ref int value)
{
value = (int)NativeStream.ReadUInt32();
value = (int)UnderlyingStream.ReadUInt32();
}
/// <inheritdoc />
public override void Serialize(ref long value)
{
value = (long)NativeStream.ReadUInt64();
value = (long)UnderlyingStream.ReadUInt64();
}
/// <inheritdoc />
public override void Serialize(ref ushort value)
{
value = NativeStream.ReadUInt16();
value = UnderlyingStream.ReadUInt16();
}
/// <inheritdoc />
public override void Serialize(ref uint value)
{
value = NativeStream.ReadUInt32();
value = UnderlyingStream.ReadUInt32();
}
/// <inheritdoc />
public override void Serialize(ref ulong value)
{
value = NativeStream.ReadUInt64();
value = UnderlyingStream.ReadUInt64();
}
#pragma warning restore CS0618 // Type or member is obsolete
@ -100,7 +100,7 @@ namespace Stride.Core.Serialization
/// <inheritdoc />
public override void Serialize(ref byte value)
{
var result = NativeStream.ReadByte();
var result = UnderlyingStream.ReadByte();
if (result == -1)
throw new EndOfStreamException();
value = (byte)result;
@ -109,7 +109,7 @@ namespace Stride.Core.Serialization
/// <inheritdoc />
public override void Serialize(ref sbyte value)
{
var result = NativeStream.ReadByte();
var result = UnderlyingStream.ReadByte();
if (result == -1)
throw new EndOfStreamException();
value = (sbyte)(byte)result;
@ -121,7 +121,7 @@ namespace Stride.Core.Serialization
Reader.Read(values, offset, count);
}
/// <inheritdoc/>
public override void Serialize(Span<byte> buffer) => NativeStream.Read(buffer);
public override void Serialize(Span<byte> buffer) => UnderlyingStream.Read(buffer);
/// <inheritdoc />
public override void Flush()

Просмотреть файл

@ -20,7 +20,7 @@ namespace Stride.Core.Serialization
public BinarySerializationWriter([NotNull] Stream outputStream)
{
Writer = new BinaryWriter(outputStream);
NativeStream = outputStream;
UnderlyingStream = outputStream;
}
private BinaryWriter Writer { get; }
@ -28,56 +28,56 @@ namespace Stride.Core.Serialization
/// <inheritdoc />
public override void Serialize(ref bool value)
{
NativeStream.WriteByte(value ? (byte)1 : (byte)0);
UnderlyingStream.WriteByte(value ? (byte)1 : (byte)0);
}
#pragma warning disable CS0618 // Type or member is obsolete
/// <inheritdoc />
public override unsafe void Serialize(ref float value)
{
NativeStream.Write(Unsafe.As<float, uint>(ref value));
UnderlyingStream.Write(Unsafe.As<float, uint>(ref value));
}
/// <inheritdoc />
public override unsafe void Serialize(ref double value)
{
NativeStream.Write(Unsafe.As<double, ulong>(ref value));
UnderlyingStream.Write(Unsafe.As<double, ulong>(ref value));
}
/// <inheritdoc />
public override void Serialize(ref short value)
{
NativeStream.Write((ushort)value);
UnderlyingStream.Write((ushort)value);
}
/// <inheritdoc />
public override void Serialize(ref int value)
{
NativeStream.Write((uint)value);
UnderlyingStream.Write((uint)value);
}
/// <inheritdoc />
public override void Serialize(ref long value)
{
NativeStream.Write((ulong)value);
UnderlyingStream.Write((ulong)value);
}
/// <inheritdoc />
public override void Serialize(ref ushort value)
{
NativeStream.Write(value);
UnderlyingStream.Write(value);
}
/// <inheritdoc />
public override void Serialize(ref uint value)
{
NativeStream.Write(value);
UnderlyingStream.Write(value);
}
/// <inheritdoc />
public override void Serialize(ref ulong value)
{
NativeStream.Write(value);
UnderlyingStream.Write(value);
}
#pragma warning restore CS0618 // Type or member is obsolete
@ -96,28 +96,28 @@ namespace Stride.Core.Serialization
/// <inheritdoc />
public override void Serialize(ref byte value)
{
NativeStream.WriteByte(value);
UnderlyingStream.WriteByte(value);
}
/// <inheritdoc />
public override void Serialize(ref sbyte value)
{
NativeStream.WriteByte((byte)value);
UnderlyingStream.WriteByte((byte)value);
}
/// <inheritdoc />
public override void Serialize([NotNull] byte[] values, int offset, int count)
{
NativeStream.Write(values, offset, count);
UnderlyingStream.Write(values, offset, count);
}
/// <inheritdoc />
public override void Serialize(Span<byte> buffer) => NativeStream.Write(buffer);
public override void Serialize(Span<byte> buffer) => UnderlyingStream.Write(buffer);
/// <inheritdoc />
public override void Flush()
{
NativeStream.Flush();
UnderlyingStream.Flush();
}
}
}

Просмотреть файл

@ -1,93 +0,0 @@
// 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;
namespace Stride.Core.Serialization
{
/// <summary>
/// Empty implementation of <see cref="SerializationStream"/>.
/// </summary>
[Obsolete] // not used
public class NullSerializationStream : SerializationStream
{
/// <inheritdoc/>
public override void Serialize(ref bool value)
{
}
/// <inheritdoc/>
public override void Serialize(ref float value)
{
}
/// <inheritdoc/>
public override void Serialize(ref double value)
{
}
/// <inheritdoc/>
public override void Serialize(ref short value)
{
}
/// <inheritdoc/>
public override void Serialize(ref int value)
{
}
/// <inheritdoc/>
public override void Serialize(ref long value)
{
}
/// <inheritdoc/>
public override void Serialize(ref ushort value)
{
}
/// <inheritdoc/>
public override void Serialize(ref uint value)
{
}
/// <inheritdoc/>
public override void Serialize(ref ulong value)
{
}
/// <inheritdoc/>
public override void Serialize(ref string value)
{
}
/// <inheritdoc/>
public override void Serialize(ref char value)
{
}
/// <inheritdoc/>
public override void Serialize(ref byte value)
{
}
/// <inheritdoc/>
public override void Serialize(ref sbyte value)
{
}
/// <inheritdoc/>
public override void Serialize(byte[] values, int offset, int count)
{
}
/// <inheritdoc/>
public override void Serialize(Span<byte> memory)
{
}
/// <inheritdoc/>
public override void Flush()
{
}
}
}

Просмотреть файл

@ -13,19 +13,6 @@ namespace Stride.Core.Serialization
{
protected const int BufferTLSSize = 1024;
// Helper buffer for classes needing it.
// If null, it should be initialized with BufferTLSSize constant.
[Obsolete("Let the caller provide a buffer.")]
protected static byte[] bufferTLS;
/// <summary>
/// The <see cref="Stream"/> from which this serializer reads or to which it writes.
/// </summary>
[Obsolete("Use UnderlyingStream instead.")]
public Stream NativeStream {
get => UnderlyingStream;
protected set => UnderlyingStream = value;
}
/// <summary>
/// The <see cref="Stream"/> from which this serializer reads or to which it writes.
/// </summary>

Просмотреть файл

@ -326,9 +326,9 @@ namespace Stride.Core.Serialization.Serializers
{
var span = MemoryMarshal.Cast<T, byte>(array.AsSpan());
if (mode == ArchiveMode.Deserialize)
stream.NativeStream.Read(span);
stream.UnderlyingStream.Read(span);
else if (mode == ArchiveMode.Serialize)
stream.NativeStream.Write(span);
stream.UnderlyingStream.Write(span);
}
}

Просмотреть файл

@ -8,20 +8,6 @@ namespace Stride.Core
{
public static class ServiceRegistryExtensions
{
/// <summary>
/// Gets a service instance from a specified interface contract.
/// </summary>
/// <typeparam name="T">Type of the interface contract of the service</typeparam>
/// <param name="registry">The registry.</param>
/// <returns>An instance of the requested service registered to this registry.</returns>
[CanBeNull]
[Obsolete("Use the generic overload of IServiceRegistry.GetService instead")]
public static T GetServiceAs<T>([NotNull] this IServiceRegistry registry)
where T : class
{
return registry.GetService<T>();
}
/// <summary>
/// Gets a service instance from a specified interface contract.
/// </summary>

Просмотреть файл

@ -234,25 +234,6 @@ namespace Stride.Core.Storage
public void Write<T>(ReadOnlySpan<T> buffer) where T : unmanaged
=> Write(MemoryMarshal.AsBytes(buffer));
/// <summary>
/// Writes the specified buffer to this instance.
/// </summary>
/// <param name="buffer">The buffer.</param>
[Obsolete("Use Write(ReadOnlySpan<byte>)")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Write(ref byte buffer, int length)
=> Write(MemoryMarshal.CreateReadOnlySpan(ref buffer, length));
/// <summary>
/// Writes the specified buffer to this instance.
/// </summary>
/// <typeparam name="T">Type must be a struct</typeparam>
/// <param name="data">The data.</param>
[Obsolete("Use Write(T) or Write(ReadOnlySpan<byte>)")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Write<T>(ref T data) where T : unmanaged
=> Write(data);
/// <summary>
/// Writes a buffer of byte to this builder.
/// </summary>

Просмотреть файл

@ -22,15 +22,6 @@ namespace Stride.Core
isShared = false;
}
[Obsolete("Obtain Memory<T> using GC.Allocate*Array or a Stride-specific allocator mechanism.")]
public UnmanagedArray(int length, IntPtr unmanagedDataPtr)
{
Length = length;
sizeOfT = Unsafe.SizeOf<T>();
Pointer = unmanagedDataPtr;
isShared = true;
}
public void Dispose()
{
if (!isShared)

Просмотреть файл

@ -39,243 +39,6 @@ namespace Stride.Core
/// </summary>
public static class Utilities
{
/// <summary>Copies bytes from the source address to the destination address.
/// <para>A thin wrapper around <see cref="Unsafe.CopyBlock(void*, void*, uint)"/>.</para></summary>
/// <param name="destination">The destination address.</param>
/// <param name="source">The source address.</param>
/// <param name="byteCount">The number of bytes to copy.</param>
/// <remarks>This API corresponds to the <c>unaligned.1 cpblk</c> opcode sequence.
/// No alignment assumptions are made about the <paramref name="destination"/> or <paramref name="source"/> pointers.</remarks>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void CopyMemory(nint destination, nint source, int byteCount)
=> Unsafe.CopyBlockUnaligned((void*)destination, (void*)source, (uint)byteCount);
/// <summary>
/// Compares two block of memory.
/// </summary>
/// <param name="from">The pointer to compare from.</param>
/// <param name="against">The pointer to compare against.</param>
/// <param name="sizeToCompare">The size in bytes to compare.</param>
/// <returns>True if the buffers are equivalent, false otherwise.</returns>
[Obsolete("Use Span<T>.SequenceEqual.")]
public static unsafe bool CompareMemory(nint from, nint against, int sizeToCompare)
{
var lhs = new Span<byte>((void*)from, sizeToCompare);
var rhs = new Span<byte>((void*)against, sizeToCompare);
return lhs.SequenceEqual(rhs);
}
/// <summary>Clears the memory.</summary>
/// <param name="destination">The destination address.</param>
/// <param name="value">The byte value to fill the memory with.</param>
/// <param name="sizeInBytesToClear">The size in bytes to clear.</param>
[Obsolete("Use Span<T>.Fill or System.Runtime.CompilerServices.Unsafe.InitBlockUnaligned")]
public static unsafe void ClearMemory(nint destination, byte value, int sizeInBytesToClear)
=> Unsafe.InitBlockUnaligned((void*)destination, value, (uint)sizeInBytesToClear);
/// <summary>
/// Return the sizeof a struct from a CLR. Equivalent to sizeof operator but works on generics too.
/// </summary>
/// <typeparam name="T">a struct to evaluate</typeparam>
/// <returns>sizeof this struct</returns>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.SizeOf<T>()")]
public static int SizeOf<T>() where T : struct => Unsafe.SizeOf<T>();
/// <summary>
/// Return the sizeof an array of struct. Equivalent to sizeof operator but works on generics too.
/// </summary>
/// <typeparam name="T">a struct</typeparam>
/// <param name="array">The array of struct to evaluate.</param>
/// <returns>sizeof in bytes of this array of struct</returns>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * array.Length")]
public static int SizeOf<T>(T[] array) where T : struct
=> array is null ? 0 : array.Length * Unsafe.SizeOf<T>();
/// <summary>
/// Pins the specified source and call an action with the pinned pointer.
/// </summary>
/// <typeparam name="T">The type of the structure to pin</typeparam>
/// <param name="source">The source.</param>
/// <param name="pinAction">The pin action to perform on the pinned pointer.</param>
[Obsolete("Use fixed statement with `unmanaged` type constraint. See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/fixed-statement")]
public static unsafe void Pin<T>(ref T source, Action<nint> pinAction) where T : unmanaged
{
fixed (void* ptr = &source)
pinAction((nint)ptr);
}
/// <summary>
/// Pins the specified source and call an action with the pinned pointer.
/// </summary>
/// <typeparam name="T">The type of the structure to pin</typeparam>
/// <param name="source">The source array.</param>
/// <param name="pinAction">The pin action to perform on the pinned pointer.</param>
[Obsolete("Use fixed statement with `unmanaged` type constraint. See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/fixed-statement")]
public static unsafe void Pin<T>(T[] source, [NotNull] Action<nint> pinAction) where T : unmanaged
{
// null if source is null or empty
fixed (void* ptr = source)
pinAction((nint)ptr);
}
/// <summary>
/// Covnerts a structured array to an equivalent byte array.
/// </summary>
/// <param name="source">The source.</param>
/// <returns>The byte array.</returns>
[Obsolete("Allocates. Consider using System.Runtime.InteropServices.MemoryMarshal.Cast or System.Buffers.ArrayPool<T>.Shared")]
public static unsafe byte[] ToByteArray<T>(T[] source) where T : struct
{
if (source is null) return null;
var bytes = MemoryMarshal.Cast<T, byte>(source.AsSpan());
var result = new byte[bytes.Length];
bytes.CopyTo(result);
return result;
}
/// <summary>
/// Reads the specified T data from a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to read</typeparam>
/// <param name="source">Memory location to read from.</param>
/// <returns>The data read from the memory location</returns>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")]
public static unsafe T Read<T>(nint source) where T : struct
=> Unsafe.ReadUnaligned<T>((void*)source);
/// <summary>
/// Reads the specified T data from a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to read</typeparam>
/// <param name="source">Memory location to read from.</param>
/// <param name="data">The data write to.</param>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Read<T>(nint source, ref T data) where T : struct
=> data = Unsafe.ReadUnaligned<T>((void*)source);
/// <summary>
/// Reads the specified T data from a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to read</typeparam>
/// <param name="source">Memory location to read from.</param>
/// <param name="data">The data write to.</param>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")]
public static unsafe void ReadOut<T>(nint source, out T data) where T : struct
=> data = Unsafe.ReadUnaligned<T>((void*)source);
/// <summary>
/// Reads the specified T data from a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to read</typeparam>
/// <param name="source">Memory location to read from.</param>
/// <param name="data">The data write to.</param>
/// <returns>source pointer + sizeof(T)</returns>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned. Consider pointer arithmetic or System.Runtime.CompilerServices.Unsafe.Add.")]
public static unsafe nint ReadAndPosition<T>(nint source, ref T data) where T : struct
{
data = Unsafe.ReadUnaligned<T>((void*)source);
return (nint)source + Unsafe.SizeOf<T>();
}
/// <summary>
/// Reads the specified array T[] data from a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to read</typeparam>
/// <param name="source">Memory location to read from.</param>
/// <param name="data">The data write to.</param>
/// <param name="offset">The offset in the array to write to.</param>
/// <param name="count">The number of T element to read from the memory location</param>
/// <returns>source pointer + sizeof(T) * count</returns>
[Obsolete("Use Span<T>.Copy or System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")]
public static unsafe nint Read<T>(nint source, T[] data, int offset, int count) where T : struct
{
var src = new Span<T>((void*)source, count);
src.CopyTo(data.AsSpan(offset));
return (nint)source + count * Unsafe.SizeOf<T>();
}
/// <summary>
/// Reads the specified T data from a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to read</typeparam>
/// <param name="source">Memory location to read from.</param>
/// <param name="data">The data write to.</param>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")]
internal static unsafe void UnsafeReadOut<T>(nint source, out T data)
=> data = Unsafe.ReadUnaligned<T>((void*)source);
/// <summary>
/// Writes the specified T data to a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to write</typeparam>
/// <param name="destination">Memory location to write to.</param>
/// <param name="data">The data to write.</param>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.WriteUnaligned")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Write<T>(nint destination, ref T data) where T : struct
=> Unsafe.WriteUnaligned((void*)destination, data);
/// <summary>
/// Writes the specified T data to a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to write</typeparam>
/// <param name="destination">Memory location to write to.</param>
/// <param name="data">The data to write.</param>
/// <returns>destination pointer + sizeof(T)</returns>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.WriteUnaligned. Consider pointer arithmetic or System.Runtime.CompilerServices.Unsafe.Add.")]
public static unsafe nint WriteAndPosition<T>(nint destination, ref T data) where T : struct
{
Unsafe.WriteUnaligned((void*)destination, data);
return (nint)destination + Unsafe.SizeOf<T>();
}
/// <summary>
/// Writes the specified T data to a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to write</typeparam>
/// <param name="destination">Memory location to write to.</param>
/// <param name="data">The data to write.</param>
[Obsolete("Use System.Runtime.CompilerServices.Unsafe.WriteUnaligned")]
internal static unsafe void UnsafeWrite<T>(nint destination, ref T data)
=> Unsafe.WriteUnaligned((void*)destination, data);
/// <summary>
/// Writes the specified array T[] data to a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to write</typeparam>
/// <param name="destination">Memory location to write to.</param>
/// <param name="data">The array of T data to write.</param>
/// <param name="offset">The offset in the array to read from.</param>
/// <param name="count">The number of T element to write to the memory location</param>
[Obsolete("Use Span<T>.CopyTo or System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")]
public static void Write<T>(byte[] destination, T[] data, int offset, int count) where T : struct
{
var src = MemoryMarshal.Cast<T, byte>(data.AsSpan(offset, count));
if (destination.Length < src.Length)
throw new ArgumentException("The destination array is too short.", nameof(destination));
src.CopyTo(destination);
}
/// <summary>
/// Writes the specified array T[] data to a memory location.
/// </summary>
/// <typeparam name="T">Type of a data to write</typeparam>
/// <param name="destination">Memory location to write to.</param>
/// <param name="data">The array of T data to write.</param>
/// <param name="offset">The offset in the array to read from.</param>
/// <param name="count">The number of T element to write to the memory location</param>
/// <returns>destination pointer + sizeof(T) * count</returns>
[Obsolete("Use Span<T>.CopyTo or System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")]
public static unsafe nint Write<T>(nint destination, T[] data, int offset, int count) where T : struct
{
var src = MemoryMarshal.Cast<T, byte>(data.AsSpan(offset, count));
var dst = new Span<byte>((void*)destination, src.Length);
src.CopyTo(dst);
return (nint)destination + src.Length;
}
/// <summary>
/// Allocate an aligned memory buffer.
/// </summary>
@ -348,90 +111,34 @@ namespace Stride.Core
}
}
/// <summary>
/// String helper join method to display an array of object as a single string.
/// </summary>
/// <param name="separator">The separator.</param>
/// <param name="array">The array.</param>
/// <returns>a string with array elements serparated by the seperator</returns>
[Obsolete("Use string.Join")]
[NotNull]
public static string Join<T>(string separator, T[] array)
=> string.Join(separator, array);
/// <summary>
/// String helper join method to display an enumrable of object as a single string.
/// </summary>
/// <param name="separator">The separator.</param>
/// <param name="elements">The enumerable.</param>
/// <returns>a string with array elements serparated by the seperator</returns>
[Obsolete("Use string.Join")]
[NotNull]
public static string Join(string separator, [NotNull] IEnumerable elements)
=> string.Join(separator, elements);
/// <summary>
/// String helper join method to display an enumrable of object as a single string.
/// </summary>
/// <param name="separator">The separator.</param>
/// <param name="elements">The enumerable.</param>
/// <returns>a string with array elements serparated by the seperator</returns>
[Obsolete("Use string.Join")]
[NotNull]
public static string Join(string separator, [NotNull] IEnumerator elements)
{
static IEnumerable<object> Enumerate(IEnumerator elements)
{
while (elements.MoveNext()) yield return elements.Current;
}
return string.Join(separator, Enumerate(elements));
}
/// <summary>
/// Read stream to a byte[] buffer
/// </summary>
/// <param name = "stream">input stream</param>
/// <returns>a byte[] buffer</returns>
[Obsolete("Allocates. Read into the destination.")]
[NotNull]
public static byte[] ReadStream([NotNull] Stream stream)
{
var readLength = 0;
return ReadStream(stream, ref readLength);
}
/// <summary>
/// Read stream to a byte[] buffer
/// </summary>
/// <param name = "stream">input stream</param>
/// <param name = "readLength">length to read</param>
/// <returns>a byte[] buffer</returns>
[Obsolete("Allocates. Read into the destination.")]
[NotNull]
public static byte[] ReadStream([NotNull] Stream stream, ref int readLength)
{
Debug.Assert(stream != null);
Debug.Assert(stream.CanRead);
var count = readLength;
Debug.Assert(count <= (stream.Length - stream.Position));
if (count == 0) {
readLength = (int)(stream.Length - stream.Position);
count = readLength;
}
Debug.Assert(count >= 0);
if (count == 0)
return Array.Empty<byte>();
var readLength = (int)(stream.Length - stream.Position);
var buffer = new byte[count];
var bytesRead = 0;
if (count > 0)
Debug.Assert(readLength <= (stream.Length - stream.Position));
if (readLength == 0)
{
do
{
bytesRead += stream.Read(buffer, bytesRead, readLength - bytesRead);
} while (bytesRead < readLength);
return Array.Empty<byte>();
}
var buffer = new byte[readLength];
var bytesRead = 0;
while (bytesRead < readLength)
{
bytesRead += stream.Read(buffer, bytesRead, readLength - bytesRead);
}
return buffer;
}
@ -490,54 +197,6 @@ namespace Stride.Core
return hashCode;
}
/// <summary>
/// Compares two collection, element by elements.
/// </summary>
/// <param name="left">A "from" enumerator.</param>
/// <param name="right">A "to" enumerator.</param>
/// <returns>True if lists are identical. False otherwise.</returns>
[Obsolete("Use SequenceEqualAllowNull")]
public static bool Compare(IEnumerable left, IEnumerable right)
{
if (ReferenceEquals(left, right)) return true;
if (left is null || right is null) return false;
return left.Cast<object>().SequenceEqual(right.Cast<object>());
}
/// <summary>
/// Compares two collection, element by elements.
/// </summary>
/// <param name="leftIt">A "from" enumerator.</param>
/// <param name="rightIt">A "to" enumerator.</param>
/// <returns>True if lists are identical. False otherwise.</returns>
[Obsolete("Use SequenceEqualAllowNull")]
public static bool Compare(IEnumerator leftIt, IEnumerator rightIt)
{
if (ReferenceEquals(leftIt, rightIt))
return true;
if (leftIt is null || rightIt is null)
return false;
bool hasLeftNext;
bool hasRightNext;
while (true)
{
hasLeftNext = leftIt.MoveNext();
hasRightNext = rightIt.MoveNext();
if (!hasLeftNext || !hasRightNext)
break;
if (!Equals(leftIt.Current, rightIt.Current))
return false;
}
// If there is any left element
if (hasLeftNext != hasRightNext)
return false;
return true;
}
/// <summary>
/// Compares two collection, element by elements.
/// </summary>
@ -586,31 +245,6 @@ namespace Stride.Core
return true;
}
[Obsolete("Use StrideCoreExtensions.SequenceEqualAllowNull")]
public static bool Compare<T>(T[] left, T[] right)
=> left.SequenceEqualAllowNull(right, null);
/// <summary>
/// Compares two collection, element by elements.
/// </summary>
/// <param name="left">The collection to compare from.</param>
/// <param name="right">The colllection to compare to.</param>
/// <returns>True if lists are identical (but no necessarely of the same time). False otherwise.</returns>
[Obsolete("Use StrideCoreExtensions.SequenceEqualAllowNull")]
public static bool Compare<T>(ICollection<T> left, ICollection<T> right)
=> left.SequenceEqualAllowNull(right, null);
/// <summary>
/// Compares two list, element by elements.
/// </summary>
/// <param name="left">The list to compare from.</param>
/// <param name="right">The colllection to compare to.</param>
/// <returns>True if lists are sequentially equal. False otherwise.</returns>
/// <remarks>Concrete List is favored over interface to avoid enumerator object allocation.</remarks>
[Obsolete("Use StrideCoreExtensions.SequenceEqualAllowNull")]
public static bool Compare<T>(List<T> left, List<T> right)
=> left.SequenceEqualAllowNull(right, null);
/// <summary>
/// Swaps the value between two references.
/// </summary>
@ -619,24 +253,6 @@ namespace Stride.Core
/// <param name="right">The right value.</param>
public static void Swap<T>(ref T left, ref T right) => (right, left) = (left, right);
/// <summary>Suspends the current thread for a duration.</summary>
/// <param name="duration">The duration of sleep. Must be non-negative.</param>
public static void Sleep(TimeSpan duration)
{
if (duration.Ticks < 0)
throw new ArgumentOutOfRangeException(nameof(duration));
Thread.Sleep(duration);
}
/// <summary>Suspends the current thread for a number of milliseconds.</summary>
/// <param name="ms">The duration in milliseconds. Must be non-negative.</param>
public static void Sleep(int ms)
{
if (ms < 0)
throw new ArgumentOutOfRangeException(nameof(ms));
Thread.Sleep(ms);
}
/// <summary>
/// Linq assisted full tree iteration and collection in a single line.
/// Warning, could be slow.

Просмотреть файл

@ -21,7 +21,7 @@ namespace Stride.Graphics.Data
var isStreamable = stream.ReadBoolean();
if (!isStreamable)
{
var image = Image.Load(stream.NativeStream);
var image = Image.Load(stream.UnderlyingStream);
textureData.InitializeFrom(image);
}
else
@ -41,7 +41,7 @@ namespace Stride.Graphics.Data
}
else
{
textureData.Save(stream.NativeStream, ImageFileType.Stride);
textureData.Save(stream.UnderlyingStream, ImageFileType.Stride);
}
}

Просмотреть файл

@ -30,7 +30,7 @@ namespace Stride.Graphics.Data
texturesStreamingProvider?.UnregisterTexture(texture);
// TODO: Error handling?
using (var textureData = Image.Load(stream.NativeStream))
using (var textureData = Image.Load(stream.UnderlyingStream))
{
if (texture.GraphicsDevice != null)
texture.OnDestroyed(); //Allows fast reloading todo review maybe?
@ -75,7 +75,7 @@ namespace Stride.Graphics.Data
// Load initial texture (with limited number of mipmaps)
if (storageHeader.InitialImage)
{
using (var textureData = Image.Load(stream.NativeStream))
using (var textureData = Image.Load(stream.UnderlyingStream))
{
if (texture.GraphicsDevice != null)
texture.OnDestroyed(); //Allows fast reloading todo review maybe?
@ -102,7 +102,7 @@ namespace Stride.Graphics.Data
// Load initial texture and discard it (we are going to load the full chunk texture right after)
if (storageHeader.InitialImage)
{
using (var textureData = Image.Load(stream.NativeStream))
using (var textureData = Image.Load(stream.UnderlyingStream))
{
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// 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;
@ -22,7 +22,7 @@ namespace Stride.Graphics.Data
var graphicsDeviceService = services.GetSafeServiceAs<IGraphicsDeviceService>();
// TODO: Error handling?
using (var textureData = Image.Load(stream.NativeStream))
using (var textureData = Image.Load(stream.UnderlyingStream))
{
if (texture.GraphicsDevice != null)
texture.OnDestroyed(); //Allows fast reloading todo review maybe?
@ -51,7 +51,7 @@ namespace Stride.Graphics.Data
if (textureData == null)
throw new InvalidOperationException("Trying to serialize a Texture without CPU info.");
textureData.Image.Save(stream.NativeStream, ImageFileType.Stride);
textureData.Image.Save(stream.UnderlyingStream, ImageFileType.Stride);
}
}

Просмотреть файл

@ -117,13 +117,13 @@ namespace Stride.Graphics.Data
PixelBuffers = pixelBuffers,
};
// TODO: We end up duplicating some of the texture data; we could find a way to avoid that by saving only the chunks of higher level mips?
initialImage.Save(stream.NativeStream, ImageFileType.Stride);
initialImage.Save(stream.UnderlyingStream, ImageFileType.Stride);
}
}
else
{
// Write whole image (old texture content serialization)
Image.Save(stream.NativeStream, ImageFileType.Stride);
Image.Save(stream.UnderlyingStream, ImageFileType.Stride);
}
}
}

Просмотреть файл

@ -149,7 +149,8 @@ namespace Stride.Shaders.Compiler.OpenGL
using (var stream = new MemoryStream())
{
BinarySerialization.Write(stream, shaderBytecodes);
var writer = new BinarySerializationWriter(stream);
writer.Write(shaderBytecodes);
rawData = stream.ToArray();
}

Просмотреть файл

@ -13,12 +13,12 @@ namespace Stride.Graphics
{
if (context.Mode == ArchiveMode.Deserialize)
{
var image = Image.Load(stream.NativeStream);
var image = Image.Load(stream.UnderlyingStream);
textureData.InitializeFrom(image);
}
else
{
textureData.Save(stream.NativeStream, ImageFileType.Stride);
textureData.Save(stream.UnderlyingStream, ImageFileType.Stride);
}
}