using System; using System.Reflection; [assembly: AssemblyFileVersion("4.0.0.0")] [assembly: AssemblyInformationalVersion("4.0.0.0")] [assembly: AssemblyTitle("System.Runtime.CompilerServices.Unsafe")] [assembly: AssemblyDescription("System.Runtime.CompilerServices.Unsafe")] [assembly: AssemblyMetadata(".NETFrameworkAssembly", "")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyCompany("Microsoft Corporation")] [assembly: AssemblyProduct("Microsoft® .NET Framework")] [assembly: CLSCompliant(false)] namespace System.Runtime.CompilerServices { public static class Unsafe { [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static T Read(void* source) { return *(T*)source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static T ReadUnaligned(void* source) { return *(T*)source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static T ReadUnaligned(ref byte source) { return *(T*)(&source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void Write(void* destination, T value) { *(T*)destination = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void WriteUnaligned(void* destination, T value) { *(T*)destination = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void WriteUnaligned(ref byte destination, T value) { *(T*)(&destination) = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void Copy(void* destination, ref T source) { *(T*)destination = source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void Copy(ref T destination, void* source) { destination = *(T*)source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void* AsPointer(ref T value) { return &value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static int SizeOf() { return sizeof(T); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void CopyBlock(void* destination, void* source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlock(destination, source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CopyBlock(ref byte destination, ref byte source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlock(ref destination, ref source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void CopyBlockUnaligned(void* destination, void* source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlockUnaligned(destination, source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CopyBlockUnaligned(ref byte destination, ref byte source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlockUnaligned(ref destination, ref source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void InitBlock(void* startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlock(startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void InitBlock(ref byte startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlock(ref startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void InitBlockUnaligned(void* startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlockUnaligned(startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlockUnaligned(ref startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T As(object o) where T : class { return (T)o; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static ref T AsRef(void* source) { return ref *(T*)source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T AsRef(in T source) { return ref source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static ref TTo As(ref TFrom source) { return ref *(TTo*)(&source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Unbox(object box) where T : struct { return ref (T)box; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Add(ref T source, int elementOffset) { return ref Unsafe.Add(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void* Add(void* source, int elementOffset) { return (byte*)source + (long)elementOffset * (long)sizeof(T); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Add(ref T source, IntPtr elementOffset) { return ref Unsafe.Add(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T AddByteOffset(ref T source, IntPtr byteOffset) { return ref Unsafe.AddByteOffset(ref source, byteOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Subtract(ref T source, int elementOffset) { return ref Unsafe.Subtract(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void* Subtract(void* source, int elementOffset) { return (byte*)source - (long)elementOffset * (long)sizeof(T); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Subtract(ref T source, IntPtr elementOffset) { return ref Unsafe.Subtract(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T SubtractByteOffset(ref T source, IntPtr byteOffset) { return ref Unsafe.SubtractByteOffset(ref source, byteOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IntPtr ByteOffset(ref T origin, ref T target) { return Unsafe.ByteOffset(ref target, ref origin); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AreSame(ref T left, ref T right) { return (ref left) == (ref right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAddressGreaterThan(ref T left, ref T right) { return (ref left) > (ref right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAddressLessThan(ref T left, ref T right) { return (ref left) < (ref right); } } }