-
Notifications
You must be signed in to change notification settings - Fork 47
Accessing private class members (Reflection)
Linniel Driver-Williams edited this page May 17, 2026
·
5 revisions
Important
That said, if there is no other way, this page outlines the 3 key ways of accessing private class members (eg. private fields, methods) from your code.
Publicizer is a library that allows you to access private fields via at compile time.
If you have having red linting lines after adding a new publicized field, clean your solution and then rebuild. (in Rider: click Build in the top menu, then Clean Solution)
<PropertyGroup>
<PublicizerClearCacheOnClean>true</PublicizerClearCacheOnClean>
</PropertyGroup>
<ItemGroup>
<Publicize Include="sts2:MegaCrit.Sts2.Core.Commands.Builders.AttackCommand._combatState"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Alchyr.Sts2.BaseLib" Version="*" PrivateAssets="All"/>
<PackageReference Include="Alchyr.Sts2.ModAnalyzers" Version="*"/>
<PackageReference Include="Krafs.Publicizer" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>