Skip to content

Enhance OptionObject and RowObject helpers with locking and unlocking…#295

Merged
scottolsonjr merged 3 commits intomainfrom
170-implement-setlockedfield-and-setunlockedfield-methods
Mar 8, 2026
Merged

Enhance OptionObject and RowObject helpers with locking and unlocking…#295
scottolsonjr merged 3 commits intomainfrom
170-implement-setlockedfield-and-setunlockedfield-methods

Conversation

@scottolsonjr
Copy link
Contributor

Enhance OptionObject and RowObject helpers with locking and unlocking functionality

  • Added methods to lock and unlock fields in OptionObject2 and OptionObject.
  • Introduced validation for field numbers to ensure they are not null or empty.
  • Improved error handling for cases where no matching field objects are found.
  • Refactored existing methods to reduce code duplication and improve readability.
  • Updated documentation to reflect new methods and their usage.

… functionality

- Added methods to lock and unlock fields in OptionObject2 and OptionObject.
- Introduced validation for field numbers to ensure they are not null or empty.
- Improved error handling for cases where no matching field objects are found.
- Refactored existing methods to reduce code duplication and improve readability.
- Updated documentation to reflect new methods and their usage.
@scottolsonjr scottolsonjr linked an issue Mar 7, 2026 that may be closed by this pull request
- Introduced a new ArgumentGuards class to centralize validation logic for field numbers and field objects.
- Replaced inline validation code in OptionObject2Helpers, OptionObjectHelpers, and RowObjectHelpers with calls to ArgumentGuards methods.
- Removed redundant constant messages from helper classes, utilizing those defined in ArgumentGuards instead.
- Improved code readability and maintainability by consolidating validation logic.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the *.Helpers layer by adding lock/unlock operations for FieldObject across RowObject, FormObject, and the OptionObject* variants, while centralizing argument validation and updating unit tests/documentation to reflect the new behavior.

Changes:

  • Added SetLocked* / SetUnlocked* helper methods for RowObject, FormObject, OptionObject, OptionObject2, and OptionObject2015.
  • Introduced a shared ArgumentGuards utility for consistent validation/normalization of field numbers and field object lists.
  • Refactored tests by splitting OptionObject helper tests per type and updating expectations to match the new exception-based validation behavior.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/ArgumentGuards.cs New shared guard/normalization helpers used by the extension methods.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RowObjectHelpers.cs Adds per-field and multi-field lock/unlock helpers; changes missing-field behavior to throw for these operations.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FormObjectHelpers.cs Adds lock/unlock helpers and applies centralized field number validation + “no matches” error handling.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObjectHelpers.cs Adds lock/unlock helpers and refactors enable/disable to use ArgumentGuards.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2Helpers.cs Same as above for OptionObject2.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2015Helpers.cs Same as above for OptionObject2015.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/ArgumentGuardsTests.cs New unit tests for ArgumentGuards.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/RowObjectHelpersTests.cs Updates test naming + adds coverage for new lock/unlock behavior and new guard-based exception cases.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/FormObjectHelpersTests.cs Updates test naming + adds coverage for new lock/unlock behavior and new guard-based exception cases.
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/OptionObjectHelpersTests.cs Removes the combined OptionObject/OptionObject2/OptionObject2015 test file (replaced by per-type files).
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/OptionObjectHelpers.OptionObject.Tests.cs New OptionObject-specific helper tests (including lock/unlock).
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/OptionObjectHelpers.OptionObject2.Tests.cs New OptionObject2-specific helper tests (including lock/unlock).
dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/OptionObjectHelpers.OptionObject2015.Tests.cs New OptionObject2015-specific helper tests (including lock/unlock).
.github/instructions/dotnet.instructions.md Documents the test naming pattern and the per-type OptionObject test file organization.
Comments suppressed due to low confidence (3)

dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObjectHelpers.cs:252

  • SetDisabledField checks that any form contains the field number, but then calls form.SetDisabledField(fieldNumber) for every form. With the new FormObject.SetDisabledField behavior (throws when the field is not present in that form), this will throw as soon as the OptionObject contains a form that does not include the field. Consider iterating only over forms where IsFieldPresent(fieldNumber) (same applies to SetEnabledField, SetLockedField, SetUnlockedField).
            if (!optionObject.Forms.Any(f => f.IsFieldPresent(fieldNumber)))
                throw new ArgumentException(ArgumentGuards.NoMatchingFieldObjectsMessage, nameof(fieldNumber));

            foreach (var form in optionObject.Forms)
            {
                form.SetDisabledField(fieldNumber);
            }

dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2Helpers.cs:82

  • SetDisabledField validates that at least one form contains the field number, but then invokes form.SetDisabledField(fieldNumber) on every form. Because FormObject.SetDisabledField now throws when the field doesn't exist in that form, this will fail when the OptionObject2 includes forms without that field. Consider only calling into forms where IsFieldPresent(fieldNumber) (same applies to SetEnabledField, SetLockedField, SetUnlockedField).
            if (!optionObject.Forms.Any(f => f.IsFieldPresent(fieldNumber)))
                throw new ArgumentException(ArgumentGuards.NoMatchingFieldObjectsMessage, nameof(fieldNumber));

            foreach (var form in optionObject.Forms)
            {
                form.SetDisabledField(fieldNumber);
            }

dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2015Helpers.cs:102

  • SetDisabledField checks that at least one form contains the field number, but then calls form.SetDisabledField(fieldNumber) for every form. With the updated FormObject.SetDisabledField throwing when the field doesn't exist in that form, this will throw for OptionObject2015 instances that contain other forms without that field. Consider only calling into forms where IsFieldPresent(fieldNumber) (same applies to SetEnabledField, SetLockedField, SetUnlockedField).
            if (!optionObject.Forms.Any(f => f.IsFieldPresent(fieldNumber)))
                throw new ArgumentException(ArgumentGuards.NoMatchingFieldObjectsMessage, nameof(fieldNumber));

            foreach (var form in optionObject.Forms)
            {
                form.SetDisabledField(fieldNumber);
            }

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2026

@scottolsonjr scottolsonjr merged commit 3bbfc49 into main Mar 8, 2026
7 checks passed
@scottolsonjr scottolsonjr deleted the 170-implement-setlockedfield-and-setunlockedfield-methods branch March 8, 2026 02:20
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.

Implement SetLockedField and SetUnlockedField Methods

2 participants