Nukepayload2.CodeAnalysis.ExtendRestrictedTypes
1.0.2-beta
dotnet add package Nukepayload2.CodeAnalysis.ExtendRestrictedTypes --version 1.0.2-beta
NuGet\Install-Package Nukepayload2.CodeAnalysis.ExtendRestrictedTypes -Version 1.0.2-beta
<PackageReference Include="Nukepayload2.CodeAnalysis.ExtendRestrictedTypes" Version="1.0.2-beta"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Nukepayload2.CodeAnalysis.ExtendRestrictedTypes" Version="1.0.2-beta" />
<PackageReference Include="Nukepayload2.CodeAnalysis.ExtendRestrictedTypes"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Nukepayload2.CodeAnalysis.ExtendRestrictedTypes --version 1.0.2-beta
#r "nuget: Nukepayload2.CodeAnalysis.ExtendRestrictedTypes, 1.0.2-beta"
#:package Nukepayload2.CodeAnalysis.ExtendRestrictedTypes@1.0.2-beta
#addin nuget:?package=Nukepayload2.CodeAnalysis.ExtendRestrictedTypes&version=1.0.2-beta&prerelease
#tool nuget:?package=Nukepayload2.CodeAnalysis.ExtendRestrictedTypes&version=1.0.2-beta&prerelease
RefStructHelper
This is a .NET analyzer project designed to extend the concept of restricted types to all ref structs in Visual Basic.
This analyzer detects various operations that could throw InvalidProgramException when using restricted types.
What are Restricted Types?
Restricted types (called ref struct in C#) are structures with the System.Runtime.CompilerServices.IsByRefLikeAttribute attribute. These types:
- Can only be allocated on the stack (cannot be boxed)
- Cannot nest
ByRef - Have usage restrictions related to stack references (scoped/unscoped ref) to ensure memory safety
Current Implementation
Completed Features
- BCX31394: Detects violations of restricted types being converted to
ObjectorValueType - BCX31396: Restrictions on converting restricted types to
Nullable(Of T)and related limitations - BCX32061: Restrictions on using restricted types as generic parameters
- BCX36598: Prevent boxing of restricted types in LINQ
- BCX36640: Prevent boxing of restricted types in Lambda closures
- BCX37052: Restrictions on restricted type variables in Async/Iterator state machines
- BCX31393: Prevent boxing when calling instance methods inherited by restricted types
en-USandzh-CNLocalization support for diagnostic messages
Future Plans
- Flow analysis for returning restricted types (
scopedandunscoped) - Flow analysis for declaring variables of restricted types in
AsyncorIteratormethods - Respect the
allows ref structconstraint - More resource translations
Project Structure
RefStructHelper/ # Main analyzer project
RefStructHelper.Demo/ # Demo project
RefStructHelper.Tests/ # Test project
Installation and Usage
Requirements
- .NET SDK that supports Visual Basic 17.13 or later
Via NuGet Package Manager
Via Project Reference
Add the following configuration to the target project's .vbproj file to enable the analyzer:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\RefStructHelper\RefStructHelper.vbproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
License
Please see the LICENSE file for licensing information.
Related Resources
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Nukepayload2.CodeAnalysis.ExtendRestrictedTypes:
| Package | Downloads |
|---|---|
|
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 runtime dependencies. - Supports addition, subtraction, increment, decrement, equality, inequality, greater than, greater than or equal, less than, and less than or equal operator. - Provides helper types and functions for easier code conversion from C#, C++, or Classic VB to VB.NET. - Runtime-check for the use of InteriorPointer(Of T) is enabled. 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) |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.2-beta | 190 | 8/30/2025 |
| 1.0.1-beta | 175 | 8/30/2025 |
| 1.0.0-beta | 175 | 8/30/2025 |
Initial beta release with comprehensive ref struct boxing detection for VB.NET.