SafelyUnsafe 1.0.0
dotnet add package SafelyUnsafe --version 1.0.0
NuGet\Install-Package SafelyUnsafe -Version 1.0.0
<PackageReference Include="SafelyUnsafe" Version="1.0.0" />
paket add SafelyUnsafe --version 1.0.0
#r "nuget: SafelyUnsafe, 1.0.0"
// Install SafelyUnsafe as a Cake Addin #addin nuget:?package=SafelyUnsafe&version=1.0.0 // Install SafelyUnsafe as a Cake Tool #tool nuget:?package=SafelyUnsafe&version=1.0.0
SafelyUnsafe
About
SafelyUnsafe provides System.Runtime.CompilerServices.Unsafe
with a "little" more safety Wrapper Method.
And also provides several support methods.
- It is implemented in the
UnsafeUnmanaged
class. In most cases, you just replaceUnsafe
toUnsafeUnmanaged
. - All type argument is restricted to
unmanaged
- overload for
ref readonly
, with anReadOnly
in the suffix. - Utility methods like
OffsetOf
,Overlaps
,NullRef
,IsNullRef
. - .NET Standard 2.0 is supported.
All generic type argument is restricted to unmanaged
Design of System.Runtime.CompilerServices.Unsafe
is older than C# 7.3.
There are no restrictions on type arguments of the Unsafe
class, but all SafelyUnsafe
methods have restrictions.
Overload for ref readonly
References that do not require the change are given the IsReadOnly
attribute(a.k.a in
keyword).
They have the ReadOnly
attribute at the end.
NOTE: in
is optional, callers should be careful.
Utility methods
MoveBlock
It is a method that can correctly copy overlapping regions, like memmove
.
The behavior of Unsafe.CopyBlock
is unspecified if the source and destination areas overlap.
This method is not implemented.
OffsetOf
It is similar to the C's offsetof
macro.
struct Foo
{
public int bar;
public int baz;
}
UnsafeUnmanaged.OffsetOf(f, f.baz); // 4
Overlaps
Determines whether two region overlap in memory.
NullRef
Get a null reference for interoperability.
In C++, it is similar to (T&)(*((T*)nullptr))
.
IsNullRef
Determines if it is a null reference.
UnsignedSizeOf
Same as Unsafe.dSizeOf
, which casts to unsigned.
AsByteRef
Reinterpret a reference to T
as a reference to byte
.
IsAddressGeq
Same as AreSame || IsAddressGreaterThan
.
IsAddressLeq
Same as AreSame || IsAddressLessThan
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 1,972 | 7/16/2020 |