C
C#3w ago
joo

Source code generation not working with partial record, only with partial class

Using a basic incremental source code generator to generate some serializer-like functionality.
c#
[Generators.Pkt]
public partial record/class ChatMsgReq
{
public int Ticks { get; set; }
public required string Msg { get; set; }
public bool OnlyBalloon { get; set; }
}
c#
[Generators.Pkt]
public partial record/class ChatMsgReq
{
public int Ticks { get; set; }
public required string Msg { get; set; }
public bool OnlyBalloon { get; set; }
}
Generated Code: * Record:
c#

// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial record ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
c#

// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial record ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
* Class:
c#
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial class ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
c#
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial class ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
With class I can access DecodePacket and EncodePacket just fine, however for the record I'm unable to access It. Also If I copy the partial record without any source code just below the original record It works fine aswell. Any Idea why this isn't working for records?
4 Replies
ero
ero3w ago
nope, no idea, looks good you should test it like does the code actually generate? are there diagnostics? step through the generator to see what it's doing
joo
jooOP3w ago
Yea that's straight up from Source Generators in Rider. However I've restarted Rider and now It works maybe that's some incremental caching problem then. I should probably try to see If I can reproduce + report It later, thanks tho
ero
ero3w ago
it's very likely a caching thing, not sure how the experience is in rider. i don't usually "test" my generators by using them in another project i just write actual tests
joo
jooOP3w ago
Hmm I'll read into that a bit more, just testing them out abit for now
Want results from more Discord servers?
Add your server