Skip to content

Convert all model and response classes to C# records#367

Open
oschwald wants to merge 1 commit intomainfrom
greg/eng-3437
Open

Convert all model and response classes to C# records#367
oschwald wants to merge 1 commit intomainfrom
greg/eng-3437

Conversation

@oschwald
Copy link
Member

@oschwald oschwald commented Mar 3, 2026

Summary

  • All response classes in MaxMind.MinFraud.Response converted from classes to records
  • All request classes in MaxMind.MinFraud.Request converted from classes to records
  • All request class constructors marked [Obsolete] — use object initializer syntax
  • SetLocales removed from IPAddress in favor of immutable WithLocales pattern via with expressions
  • CustomInputs intentionally unchanged (builder pattern, no benefit from records)

Depends on: maxmind/GeoIP2-dotnet#420 (GeoIP2 records conversion)

Note: The MaxMind.MinFraud.csproj currently uses a ProjectReference to the local GeoIP2 worktree for development. This must be reverted to a PackageReference pointing to the released GeoIP2 package before merging.

Test plan

  • All 534 MinFraud tests pass across net8.0/net9.0/net10.0
  • All 447 GeoIP2 tests pass
  • No SetLocales references remain in MinFraud
  • No class declarations remain in Response/ or Request/ (except CustomInputs)
  • Revert ProjectReferencePackageReference after GeoIP2 v6 release

🤖 Generated with Claude Code

All response classes in MaxMind.MinFraud.Response and request classes
in MaxMind.MinFraud.Request are now C# records, matching the GeoIP2
records conversion. Request constructors are marked [Obsolete] in
favor of object initializer syntax. SetLocales removed from
IPAddress in favor of immutable WithLocales pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly modernizes the MaxMind.MinFraud library by transitioning its core model and response classes to C# records. This change promotes immutability, simplifies object creation through initializer syntax, and aligns the codebase with contemporary C# practices. The update also refines how locales are handled for IP addresses, moving towards a more functional and immutable approach. These changes are part of a broader effort to enhance the library's robustness and maintainability, with a dependency on a future GeoIP2 release.

Highlights

  • C# Record Conversion: All response classes in MaxMind.MinFraud.Response and all request classes in MaxMind.MinFraud.Request have been converted from traditional C# classes to C# records. This change enhances immutability and simplifies data transfer objects.
  • Constructor Obsolescence: All constructors for request classes have been marked [Obsolete]. Users are now encouraged to use object initializer syntax for creating request objects, aligning with the immutability benefits of records.
  • IPAddress Locale Handling Update: The SetLocales method has been removed from MaxMind.MinFraud.Response.IPAddress. Locale handling now utilizes an immutable WithLocales pattern via with expressions, improving consistency and functional programming paradigms.
  • Dependency Update for GeoIP2: The project now references a local worktree of MaxMind.GeoIP2 for development, indicating a dependency on an upcoming GeoIP2 v6 release. This will need to be reverted to a PackageReference before merging.
Changelog
  • releasenotes.md
    • Updated version to 6.0.0.
    • Added breaking change: All response classes in MaxMind.MinFraud.Response converted from classes to records.
    • Added breaking change: All request classes in MaxMind.MinFraud.Request converted from classes to records.
    • Added breaking change: All request class constructors marked [Obsolete], encouraging object initializer syntax.
    • Added breaking change: SetLocales method removed from MaxMind.MinFraud.Response.IPAddress.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively modernizes the codebase by converting model and response classes to C# records, which enhances immutability and code clarity. The strategy of marking old constructors as [Obsolete] to guide developers towards object initializer syntax is a good one. My review includes a couple of suggestions for improvement: one is to update the unit tests to adhere to the new object initialization pattern instead of suppressing obsolescence warnings, and the other is to remove a redundant ToString() override in favor of the compiler-generated implementation for records.

Note: Security Review did not run due to the size of the PR.

<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>CS0618</NoWarn>

Choose a reason for hiding this comment

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

medium

Suppressing the CS0618 warning for obsolete members should be a temporary measure. Since this pull request aims to promote the use of object initializers by marking constructors as [Obsolete], it would be more beneficial to update the unit tests to use the new recommended syntax. This would eliminate the need for <NoWarn> and ensure the tests serve as current examples of correct API usage.

Comment on lines +8 to +12
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
public sealed override string ToString() => base.ToString();

Choose a reason for hiding this comment

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

medium

This explicit ToString() override is redundant. For a sealed record that inherits from another record and adds no new properties, the compiler-generated ToString() method provides a suitable implementation that includes the type name and properties from the base record. Removing this override will simplify the code and rely on the idiomatic behavior of records.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant