Nukepayload2.CompilerServices.InteriorPointer
1.2.0-rc1
dotnet add package Nukepayload2.CompilerServices.InteriorPointer --version 1.2.0-rc1
NuGet\Install-Package Nukepayload2.CompilerServices.InteriorPointer -Version 1.2.0-rc1
<PackageReference Include="Nukepayload2.CompilerServices.InteriorPointer" Version="1.2.0-rc1" />
<PackageVersion Include="Nukepayload2.CompilerServices.InteriorPointer" Version="1.2.0-rc1" />
<PackageReference Include="Nukepayload2.CompilerServices.InteriorPointer" />
paket add Nukepayload2.CompilerServices.InteriorPointer --version 1.2.0-rc1
#r "nuget: Nukepayload2.CompilerServices.InteriorPointer, 1.2.0-rc1"
#:package Nukepayload2.CompilerServices.InteriorPointer@1.2.0-rc1
#addin nuget:?package=Nukepayload2.CompilerServices.InteriorPointer&version=1.2.0-rc1&prerelease
#tool nuget:?package=Nukepayload2.CompilerServices.InteriorPointer&version=1.2.0-rc1&prerelease
Nukepayload2.CompilerServices.InteriorPointer
Provides functionality for manipulating interior pointers with VB.
- Convert ByRef to interior pointer, or convert interior pointer back to ByRef.
- Load or store unmanaged values indirectly.
- No extra dependencies.
- Supports addition, subtraction, increment, decrement, equality, inequality, greater than, greater than or equal, less than, and less than or equal operator.
- Provides helper functions for easier code conversion from C#, C++, or Classic VB to VB.NET.
- Runtime-check for InteriorPointer(Of T) is enabled.
Scenarios
- You don't want to see small c# projects among your huge VB solution.
- You prefer VB syntax and want to implement pointer algorithms.
- You want to convert c# codes that contain
Span(Of T)
, without marking everything<Obsolete>
. - You want to bring Classic VB codes which have
VarPtr
andStrPtr
to .NET.
Guides
Commonly used types
Nukepayload2.CompilerServices.InteriorPointer Nukepayload2.CompilerServices.Unsafe.InteriorPointer(Of T) Nukepayload2.CompilerServices.Unsafe.UnsafeOperators Nukepayload2.CompilerServices.Unsafe.PinnedPointer(Of T) Nukepayload2.CompilerServices.Unsafe.TransientPointer(Of T)
C-style operators vs InteriorPointer members
C# sample code | Remarks | InteriorPointer with VB |
---|---|---|
var value = *p; |
p is a pointer of an unmanaged type | Dim value = p.UnmanagedItem |
var value = *p++; |
p is a pointer of an unmanaged type | Dim value = p.GetAndIncrement.UnmanagedItem |
var value = *++p; |
p is a pointer of an unmanaged type | Dim value = p.IncrementAndGet.UnmanagedItem |
var value = *p--; |
p is a pointer of an unmanaged type | Dim value = p.GetAndDecrement.UnmanagedItem |
var value = *--p; |
p is a pointer of an unmanaged type | Dim value = p.DecrementAndGet.UnmanagedItem |
*p = value; |
p is a pointer of an unmanaged type | p.UnmanagedItem = value |
*p++ = value; |
p is a pointer of an unmanaged type | p.GetAndIncrement.SetUnmanagedItem(value) |
var p = (T*)Unsafe.AsPointer(ref r); |
Converts ref to raw pointer | Dim p = r.UnsafeByRefToTypedPtr |
ref T r = Unsafe.AsRef<T>((void*)p); |
p is IntPtr | Dim r = CType(p, InteriorPointer(Of T)) |
T r = Unsafe.AsRef<T>((void*)p); |
p is IntPtr | Dim r = p.UnsafePtrToByRef(Of T) |
T* r = &p; |
p is structure or T is pinned | Dim r = VarPtr(p) |
*p1 = *p2; |
p1 is a pointer of an unmanaged type | p1.CopyUnmanagedFrom(p2) |
p+=2 |
p is void* | p+=2 |
p-=2 |
p is void* | p-=2 |
p+=2 |
p is T* | p+=2 |
p-=2 |
p is T* | p-=2 |
p1 < p2 |
p1 is pointer | p1 < p2 |
p1 > p2 |
p1 is pointer | p1 > p2 |
p1 <= p2 |
p1 is pointer | p1 <= p2 |
p1 >= p2 |
p1 is pointer | p1 >= p2 |
p1 = (void*)p2 |
p1 is pointer | p1 = CType(p2, InteriorPointer) |
p1 = (T*)p2 |
p1 is pointer | p1 = CType(p2, InteriorPointer(Of T)) |
C++ sample code | Remarks | InteriorPointer with VB |
---|---|---|
auto u = static_cast<unsigned int>(signedValue) |
Converts objects that has the same size and memory layout. | Dim u = signedValue.UnsafeStaticCast(Of UInteger) |
auto u = reinterpret_cast<cow*>(wind) |
Converts between irrelevant types. | Dim u = wind.UnsafeReinterpretCast(Of Cow) |
C# pointer keywords to VB with InteriorPointer
stackalloc
C#
char* chrBuf = stackalloc char[50];
VB
<StructLayout(LayoutKind.Sequential, Size:=50 * 2)>
Structure StackAllocChar50
End Structure
Dim chrBuf As InteriorPointer(Of Char) = resultBufValue.UnsafeByRefToPtr
fixed
Fixed array
C#
char[] values = new char[4096];
fixed(char* chrBuf = &values[0])
{
// use chrBuf
}
VB
Dim values(4095) As Char
Using pinPtr = Fixed(values)
Dim chrBuf = pinPtr.Pointer
' use chrBuf
End Using
Fixed string
C#
var values = new string('0', 4096);
fixed(char* chrBuf = values)
{
// use chrBuf
}
VB
Dim values As New String("0"c, 4096)
Using pinPtr = StrPtr(values)
Dim chrBuf = pinPtr.Pointer
' use chrBuf
End Using
ref struct
C#
public ref struct StackStringBuilder {}
VB
Namespace Global.System.Runtime.CompilerServices
<CompilerGenerated>
<Embedded>
Friend NotInheritable Class IsByRefLikeAttribute
Inherits Attribute
Public Sub New()
MyBase.New()
End Sub
End Class
End Namespace
<IsByRefLike>
Public Structure StackStringBuilder
End Structure
readonly ref struct
C#
public readonly ref struct StackString {}
VB
Namespace Global.System.Runtime.CompilerServices
<CompilerGenerated>
<Embedded>
Friend NotInheritable Class IsByRefLikeAttribute
Inherits Attribute
Public Sub New()
MyBase.New()
End Sub
End Class
<CompilerGenerated>
<Embedded>
Friend NotInheritable Class IsReadOnlyAttribute
Inherits Attribute
Public Sub New()
MyBase.New()
End Sub
End Class
End Namespace
<IsByRefLike, IsReadOnly>
Public Structure StackString
End Structure
Restrictions
The InteriorPointer
and the InteriorPointer(Of T)
may lose their targets if they're used as
the data type of:
- An array element
- Field of class
- Field of structure which is a field of class (directly or indirectly)
- Anonymous type member
- Generic type argument
Async Function
locals or argumentAsync Sub
locals or argumentIterator Function
locals or argument- Lambda expression locals or argument
- Anonymous delegate locals or argument
- Locals as
Object
orValueType
- Parameters as
Object
orValueType
Static
locals
Known issues
- The compile-time checking for the unsafe use of
InteriorPointer
andInteriorPointer(Of T)
is incomplete. For more information, see VBRefStructHelper.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- Nukepayload2.CodeAnalysis.ExtendRestrictedTypes (>= 1.0.2-beta)
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.2.0-rc1 | 101 | 8/30/2025 |
1.1.3-beta8 | 662 | 12/26/2018 |
1.1.2-beta7 | 576 | 12/24/2018 |
1.0.4-beta6 | 642 | 10/13/2018 |
1.0.3-beta5 | 676 | 10/1/2018 |
1.0.2-beta4 | 697 | 10/1/2018 |
1.0.0-beta3 | 656 | 9/26/2018 |
1.0.0-beta2 | 676 | 9/24/2018 |
Fixed StrPtr for .NET 8.0 and bundled analyzer for interior pointers