C
C#8mo ago
RumTery

Hide private partial class/struct members

I am generating code based on a given class, this partial class contains a generated public interface and generated private members. Is it possible to hide the visibility of private members for the original non-generated class? Some code example
[System]
internal partial class IterativeSystem
{
[SystemCall]
public void Do(int a, ref int b)
{

}
}
[System]
internal partial class IterativeSystem
{
[SystemCall]
public void Do(int a, ref int b)
{

}
}
internal partial class IterativeSystem
{
private static Type[] _mutTypes = [typeof(int)];
private static Type[] _readTypes = [typeof(int)];
public ReadOnlySpan<Type> MutTypes => _mutTypes;
public ReadOnlySpan<Type> ReadTypes => _readTypes;

public void Update()
{
// __DoCall(IRuntimeContext.Current.World);
}

private readonly QueryDescription __DoQuery;
private void __DoCall(World world)
{
var query = world.Query(in __DoQuery);
foreach (ref var chunk in query)
{
var componentsFirst = chunk.GetFirst<int, int>();
foreach (var entityIndex in chunk)
{
ref var t0Component = ref Unsafe.Add(ref componentsFirst.t0, entityIndex);
ref var t1Component = ref Unsafe.Add(ref componentsFirst.t1, entityIndex);
Do(t0Component, ref t1Component);
}
}
}
}
internal partial class IterativeSystem
{
private static Type[] _mutTypes = [typeof(int)];
private static Type[] _readTypes = [typeof(int)];
public ReadOnlySpan<Type> MutTypes => _mutTypes;
public ReadOnlySpan<Type> ReadTypes => _readTypes;

public void Update()
{
// __DoCall(IRuntimeContext.Current.World);
}

private readonly QueryDescription __DoQuery;
private void __DoCall(World world)
{
var query = world.Query(in __DoQuery);
foreach (ref var chunk in query)
{
var componentsFirst = chunk.GetFirst<int, int>();
foreach (var entityIndex in chunk)
{
ref var t0Component = ref Unsafe.Add(ref componentsFirst.t0, entityIndex);
ref var t1Component = ref Unsafe.Add(ref componentsFirst.t1, entityIndex);
Do(t0Component, ref t1Component);
}
}
}
}
3 Replies
333fred
333fred8mo ago
No. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/file allows you to hide a separate type you define in a generated type, but it doesn't allow you to hide an entire partial part
file keyword - C# Reference - C#
file modifier: Declare types whose scope is the file in which it's declared
RumTery
RumTeryOP8mo ago
Is there any other workaround? I already created separate class with file accessor but it only helps with fields. Methods can't be moved, as they need to access other private method defined in original partial class
333fred
333fred8mo ago
No
Want results from more Discord servers?
Add your server