Skip to content

C#: Eliminate payload extraction duplication, fix GetMsgId behavior, and correct XML comment formatting#262

Merged
rijesha merged 7 commits intodevelopfrom
copilot/fix-message-class-duplicates
Feb 5, 2026
Merged

C#: Eliminate payload extraction duplication, fix GetMsgId behavior, and correct XML comment formatting#262
rijesha merged 7 commits intodevelopfrom
copilot/fix-message-class-duplicates

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

C# code generator had three issues: payload extraction logic (~15 lines) repeated in every message's Deserialize(FrameMsgInfo), messages without msgid returned 0 from GetMsgId(), and multi-line comments generated separate <summary> tags per line.

Changes

Centralized payload extraction

  • Added ExtractPayload() method to FrameMsgInfo struct handling offset/length edge cases with bounds validation
  • Reduced generated code from ~15 lines to ~6 lines per message

GetMsgId() behavior

  • Messages without msgid now throw NotSupportedException with clear error message instead of returning 0
  • Satisfies interface requirements while preventing ambiguous 0 return value

XML comment formatting

  • Added format_xml_summary() helper to generate proper single-block XML documentation
  • Fixed enum, message, field, and enum value comment generation

Example

Before:

public static Message Deserialize(FrameMsgInfo frameInfo) {
    if (frameInfo.MsgData == null) return new Message();
    byte[] payload;
    if (frameInfo.MsgDataOffset > 0) {
        payload = new byte[frameInfo.MsgLen];
        Array.Copy(frameInfo.MsgData, frameInfo.MsgDataOffset, payload, 0, frameInfo.MsgLen);
    } else {
        payload = frameInfo.MsgData;
    }
    return Deserialize(payload);
}

/// <summary>
/// Line 1
/// </summary>
/// <summary>
/// Line 2
/// </summary>

After:

public static Message Deserialize(FrameMsgInfo frameInfo) {
    if (frameInfo.MsgData == null) return new Message();
    return Deserialize(frameInfo.ExtractPayload());
}

/// <summary>
/// Line 1
/// Line 2
/// </summary>
Original prompt

This section details on the original issue you should resolve

<issue_title>C# has a few improvements</issue_title>
<issue_description>// Currently repeated in every message class
if (frameInfo.MsgDataOffset > 0)
{
payload = new byte[frameInfo.MsgLen];
Array.Copy(frameInfo.MsgData, frameInfo.MsgDataOffset, payload, 0, frameInfo.MsgLen);
}

GetMsgId() returns 0 for msgs without a msg_id. Instead these messages shouldn't have this function available or some other pattern</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 5, 2026 19:38
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
@rijesha
Copy link
Contributor

rijesha commented Feb 5, 2026

@copilot are there other places in the c# generated code where ///

is not handled correctly

Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate code in message classes C#: Centralize payload extraction and fix GetMsgId for messages without msgid Feb 5, 2026
Copilot AI requested a review from rijesha February 5, 2026 19:48
Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

@copilot are there other places in the c# generated code where ///

is not handled correctly

Your comment appears to be cut off. Could you please complete your question?

I noticed there are multiple places in the C# generator where XML documentation comments (///) might have issues:

  1. Multi-line comments get multiple <summary> tags - Currently, each comment line gets wrapped in its own <summary> tag instead of all lines being inside a single <summary> block
  2. Similar patterns in enum, message, and field comments

Are you asking about:

  • Fixing the XML comment formatting for multi-line comments?
  • Other code duplication patterns similar to the payload extraction?
  • Something else?

Please let me know so I can address your concern properly.

Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Copilot AI changed the title C#: Centralize payload extraction and fix GetMsgId for messages without msgid C#: Eliminate payload extraction duplication, fix GetMsgId behavior, and correct XML comment formatting Feb 5, 2026
@rijesha rijesha marked this pull request as ready for review February 5, 2026 20:03
@rijesha rijesha merged commit 42fc143 into develop Feb 5, 2026
1 check passed
@rijesha rijesha deleted the copilot/fix-message-class-duplicates branch February 5, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C# has a few improvements

2 participants