PointersAndWorkaroundsVB 1.0.2
See the version list below for details.
dotnet add package PointersAndWorkaroundsVB --version 1.0.2
NuGet\Install-Package PointersAndWorkaroundsVB -Version 1.0.2
<PackageReference Include="PointersAndWorkaroundsVB" Version="1.0.2" />
<PackageVersion Include="PointersAndWorkaroundsVB" Version="1.0.2" />
<PackageReference Include="PointersAndWorkaroundsVB" />
paket add PointersAndWorkaroundsVB --version 1.0.2
#r "nuget: PointersAndWorkaroundsVB, 1.0.2"
#:package PointersAndWorkaroundsVB@1.0.2
#addin nuget:?package=PointersAndWorkaroundsVB&version=1.0.2
#tool nuget:?package=PointersAndWorkaroundsVB&version=1.0.2
PointersAndWorkaroundsVB
Not just a pointer library, but a full comprehensive library tailored for VB.NET.
New in version 1.0.2: With the optimized
MakeAsyncEnumerablemethod, this library is now backward-compatible with .NET SDK 8.0 (and even .NET 9.0).
This NuGet package provides VB.NET developers with C#-like features including safe pointer operations, functional programming utilities, tuple deconstruction, and workarounds for VB.NET limitations.
The library aims to bridge the gap between VB.NET and C# features, enabling VB.NET developers to make full use of modern programming features while maintaining the safety and simplicity of the VB.NET language.
Requirements
Features
🔧 Pointer Operations
- Safe pointer management for VB.NET developers
- Enhanced MemoryBlock class with zero-initialization, span support, and array copying
- Typed pointers with bounds checking
- Array pinning to prevent GC movement
- Memory block creation from existing pointers
🧮 Functional Programming
- Pattern matching expressions
- Function composition and method chaining
- Memoization for expensive computations
- Currying and partial function application
- Pipeline operators for fluent APIs
🔄 Workarounds
- Value swapping with reference parameters
- Assignments with return values
- Type matching utilities
- Async iteration with loop control
- MakeAsyncEnumerable for converting iterator functions to async enumerables
- Safe array slicing with bounds checking
📦 Tuple Deconstruction
- Value tuple extensions for VB.NET
- Deconstruction helpers for 2-5 element tuples
- Type-safe tuple operations
Installation
# Package Manager
Install-Package PointersAndWorkaroundsVB
# .NET CLI
dotnet add package PointersAndWorkaroundsVB
# Package Reference
<PackageReference Include="PointersAndWorkaroundsVB" Version="1.0.0" />
Quick Start
Pointer Operations
Imports PointersAndWorkaroundsVB
' Create a pointer from an array
Dim numbers() As Integer = {1, 2, 3, 4, 5}
Dim ptr = Pointer.Create(numbers)
' Access elements safely
For i As Integer = 0 To Pointer.UBound(ptr)
Console.WriteLine(ptr(i))
Next
' Memory block allocation
Using memoryBlock As New MemoryBlock(1024)
' Use the memory block for unmanaged operations
Dim intPtr = memoryBlock.AsPointer(Of Integer)(256)
' ... work with the pointer
End Using
Functional Programming
Imports PointersAndWorkaroundsVB
' Pattern matching
Dim result = (3.5F).PatternMatch(
(Function(x) x < 0, "Negative"),
(Function(x) x = 0, "Zero"),
(Function(x) x > 0, "Positive")
)
' Function composition
Dim transform = (Function(x As Integer) x).Compose(
Function(n) n * 2,
Function(n) n + 1,
Function(n) n.ToString()
)
' Memoization
Dim expensiveFunction = Function(x As Integer)
' Expensive computation here
Return x * x
End Function
Dim memoized = expensiveFunction.Memoize()
Workarounds
Imports PointersAndWorkaroundsVB
' Value swapping
Dim a = 10, b = 20
Workarounds.Swap(a, b)
' Assignment with return value
Dim value = Workarounds.Assign(a, 42)
' Type matching
If Workarounds.TryMatchType(someObject, value) Then
' Use the typed value
End If
' Safe array slicing
Dim original As Integer() = {1, 2, 3, 4, 5}
Dim slice = Workarounds.Slice(original, 1, 3)
Enhanced MemoryBlock Features
Imports PointersAndWorkaroundsVB
' Create memory block with zero initialization
Using memoryBlock As New MemoryBlock(1024, zeroMemory:=True)
' Copy data from managed array
Dim sourceData() As Integer = {1, 2, 3, 4, 5}
memoryBlock.CopyFrom(sourceData)
' Work with spans for safe access
Dim span = memoryBlock.AsSpan(Of Integer)(5)
For i As Integer = 0 To span.Length - 1
span(i) *= 2 ' Modify data through span
Next i
' Copy data back to managed array
Dim resultData(4) As Integer
memoryBlock.CopyTo(resultData)
End Using
' Create memory block from existing pointer (advanced usage)
Using existingPtr As Pointer(Of Integer) = GetSomePointer()
Dim referencedBlock = MemoryBlock.FromPointer(existingPtr, 256)
' ... then work with the referenced block
End Using
Async Enumerable Support
Imports PointersAndWorkaroundsVB
' Convert iterator function to async enumerable (for .NET 8.0 & .NET 9.0)
' NOTE: For .NET 10.0, DO NOT USE the `Await` keyword.
Dim asyncNumbers = Await Workarounds.MakeAsyncEnumerable(
Iterator Function()
For i = 1 To 10 : Yield i : Next i
End Function)
' Use with async iteration
Await asyncNumbers.ForEachAsync(Function(num)
Console.WriteLine($"Processing number: {num}")
Return LoopSignal.Normal
End Function)
Tuple Deconstruction
Option Strict On
Option Infer On
Imports PointersAndWorkaroundsVB
Dim person = ("John", "Doe", 30)
' Deconstruct the tuple (ideal syntax, currently not supported)
'Dim (firstName, lastName, age) = person
' It is REALISTIC to write:
Dim firstName As String, lastName As String, age As Integer
person.Deconstruct(firstName, lastName, age)
API Reference
Pointer Class
Pointer.Create(array)- Create a typed pointer from an arrayPointer.UBound(ptr)- Get the upper bound of a pointerPointer<T>- Generic pointer class with indexer access
MemoryBlock Class
MemoryBlock(sizeInBytes, zeroMemory)- Allocate unmanaged memory with optional zero initializationMemoryBlock.Allocate<T>(elementCount)- Type-safe allocationMemoryBlock.FromPointer<T>(pointer, sizeInBytes)- Create memory block from existing Pointer(Of T)AsPointer<T>(elementCount)- Create typed pointer from memory blockFill(byte)/Fill<T>(T)- Fill memory with byte or typed valueCopyFrom<T>(array)- Copy data from managed array to memory blockCopyTo<T>(array)- Copy data from memory block to managed arrayAsSpan<T>(elementCount)- Create span for safe memory accessAsReadOnlySpan<T>(elementCount)- Create read-only span for safe memory access
Workarounds Module
Swap(ref T, ref T)- Swap two valuesAssign(ref T, T)- Assign with return valueTryMatchType(object, out T)- Type-safe matchingMakeAsyncEnumerable(enumerableFunc)- Convert iterator function to async enumerableForEachAsync- Async iteration with loop controlSlice(array, start, end)- Safe array slicingSlice(list, start, end)- Safe list slicing
FunctionalExtensions Module
PatternMatch- Pattern matching expressionsCompose- Function compositionMemoize- Function memoizationCurry- Partial function applicationPipe- Pipeline operator simulation
ValueTupleExtensions Module
Deconstructmethods for 2-5 element tuples
Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
Support
If you encounter any issues or have questions, please open an issue on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.