Files
sbox-public/engine/Tools/InteropGen/Arguments/ArgDefinedStruct.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

54 lines
1.4 KiB
C#

namespace Facepunch.InteropGen;
public class ArgDefinedStruct : Arg
{
public Struct Type { get; set; }
public ArgDefinedStruct( Struct c, string name, string[] flags )
{
Type = c;
Name = name;
Flags = flags;
}
public override string ManagedType => Type.ManagedNameWithNamespace;
public override string NativeType => Type.NativeNameWithNamespace;
public override string ManagedDelegateType => ManagedType;
public override string NativeDelegateType => NativeType;
public override string GetManagedDelegateType( bool incoming )
{
return Type.IsPointer
? $"IntPtr /* PtrHandle:{Type.NativeName} */"
: !incoming && Flags == null && !Type.IsEnum && !Type.HasAttribute( "small" )
? $"{ManagedType}*"
: base.GetManagedDelegateType( incoming );
}
public override string ReturnWrapCall( string functionCall, bool native )
{
if ( native )
{
if ( Type.CreateUsing != null )
{
functionCall = $"{Type.CreateUsing}( {functionCall} )";
}
}
return base.ReturnWrapCall( functionCall, native );
}
public override string ToInterop( bool native, string code = null )
{
return Type.IsPointer
? code ?? Name
: !native && code == null && Name != null && Flags == null && !Type.IsEnum && !Type.HasAttribute( "small" )
? $"&{Name}"
: base.ToInterop( native, code );
}
public override string DefaultValue => $"{NativeType}()";
}