Skip to content

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

Merged
horgh merged 14 commits intomainfrom
greg/eng-3437
Mar 20, 2026
Merged

Convert all model and response classes to C# records#367
horgh merged 14 commits 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

@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.

oschwald and others added 9 commits March 20, 2026 10:17
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>
With the move to object initializer syntax, the constructor
validation that ensured at least one identifier (IPAddress,
MinFraudId, MaxMindId, TransactionId) is set can be bypassed.
Move this validation to ReportAsync so it applies regardless of
how the report is constructed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convert all request test files to use `new Foo { Prop = value }` instead
of `new Foo(prop: value)`, exercising the recommended API surface. This
removes the file-wide `#pragma warning disable CS0618` from 12 test
files and the localized pragma around TestFullReportRequest.

The cross-property validation test (TestRequired) in TransactionReportTest
is replaced by TestReportRequiresIdentifier in WebServiceClientTest, since
that validation now lives only in ReportAsync.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
oschwald and others added 5 commits March 20, 2026 22:31
The old constructor intentionally suppressed Guid.Empty, but the new
object-initializer path preserved it, allowing the zero GUID to reach
the API. Normalize in the init accessor so both paths behave
consistently. Remove the now-redundant Guid.Empty check from
ReportAsync.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Without this, `new TransactionReport { IPAddress = ip }` silently
defaults Tag to NotFraud (the first enum member), sending an incorrect
report. The `required` keyword makes omitting Tag a compile-time error.

Add polyfill attributes for netstandard2.0/2.1 where
RequiredMemberAttribute and friends don't exist. Mark both obsolete
constructors with [SetsRequiredMembers] so they remain usable.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All other async methods in WebServiceClient use ConfigureAwait(false)
but ReportAsync was missing it, which could cause deadlocks in
synchronous-over-async contexts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Exercise the deprecated constructor path to verify it requires at
least one identifier, sets properties correctly, and normalizes
Guid.Empty to null.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Validation now happens at property init time and in ReportAsync, not
in constructors. Update the documentation to reflect this.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@horgh horgh merged commit 9e06637 into main Mar 20, 2026
16 checks passed
@horgh horgh deleted the greg/eng-3437 branch March 20, 2026 22:45
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.

2 participants