Skip to content

Conversation

@gewarren gewarren marked this pull request as ready for review September 30, 2025 17:53
@gewarren gewarren requested a review from a team as a code owner September 30, 2025 17:53
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I had a few optional suggestions and then, let's :shipit:

Comment on lines 73 to 88
public ReplyData(Actions action, string reply, bool returnReply)
{
this.reply = reply;
this.action = action;
this.returnReply = returnReply;
Reply = reply;
Action = action;
_returnReply = returnReply;
}

// Properties.
public string Reply { get { return reply; } }
public Actions Action { get { return action; } }
public string Reply { get; }
public Actions Action { get; }

public override string ToString()
{
return String.Format("Reply: {0} Action: {1} return? {2}",
reply, action.ToString(), returnReply.ToString());
return string.Format("Reply: {0} Action: {1} return? {2}",
Reply, Action.ToString(), _returnReply.ToString());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could just be a record, and then the body could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillWagner The example is trying to show why not to pass a reference type as a ref parameter. I'm not sure if it's as meaningful if the example passes a value type by reference. Do you still feel I should change it? Also, which "body" could be removed?

Example intro:

"The following library shows two implementations of a class that generates responses to the feedback of the user. The first implementation (BadRefAndOut) forces the library user to manage three return values. The second implementation (RedesignedRefAndOut) simplifies the user experience by returning an instance of a container class (ReplyData) that manages the data as a single unit."

{
//<snippet1>
public class Mouse
public class Mouse(int numberOfButtons, string scanType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a record as well:

public record class Mouse(int NumberOfButtons, string ScanType);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillWagner Does being a record instead of a class make it automatically serializable via binary or XML serialization? If so, then the CA rule wouldn't fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants