Skip to content

Implement COMPOBJ() function#1914

Merged
RobertvanderHulst merged 2 commits intodevfrom
feature/vfp-compobj
May 4, 2026
Merged

Implement COMPOBJ() function#1914
RobertvanderHulst merged 2 commits intodevfrom
feature/vfp-compobj

Conversation

@Irwin1985
Copy link
Copy Markdown
Contributor

Implements the COMPOBJ() function.

  • Compares the properties of two objects and returns .T. if their properties and property values are identical.
  • Uses .NET reflection to compare all public instance properties.
  • Skip indexed properties
  • Recursively compares nested objects (excluding types and strings).
  • Handles NIL cases

Copy link
Copy Markdown
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 implements the Visual FoxPro-compatible COMPOBJ() runtime function in XSharp.VFP using .NET reflection, and adds a new xUnit test suite to validate core comparison behavior.

Changes:

  • Moved COMPOBJ() from a stubbed “ToDo” implementation to a full implementation under ClassFunctions.prg.
  • Implemented property-based comparison via reflection with recursion for nested objects and special handling for NULL_OBJECT.
  • Added a new CompObjTests.prg test file and included it in the test project.

Reviewed changes

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

File Description
src/Runtime/XSharp.VFP/ToDo-C.prg Removes the old COMPOBJ() stub declaration/throw.
src/Runtime/XSharp.VFP/ClassFunctions.prg Adds the full COMPOBJ() implementation using reflection and recursive comparison.
src/Runtime/XSharp.VFP.Tests/XSharp.VFP.Tests.xsproj Includes the new CompObjTests.prg in the test build.
src/Runtime/XSharp.VFP.Tests/CompObjTests.prg Adds initial xUnit coverage for basic equality/inequality, nesting, and null handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +66 to +72
LOCAL oProp2 := NULL AS PropertyInfo
FOREACH VAR oP IN aProps2
IF oP:Name == oProp1:Name
oProp2 := oP
EXIT
ENDIF
NEXT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Applied in commit 4bf81c48. The nested FOREACH is replaced by building a Dictionary<STRING, PropertyInfo> from oExpression2's comparable properties once (O(n)), then doing O(1) ContainsKey lookups while iterating oExpression1's properties. The change also fixed the related raw Length comparison bug (which compared unfiltered arrays before indexed/unreadable properties were skipped) — now the counts of filtered properties are compared at the end of the loop.

Comment thread src/Runtime/XSharp.VFP/ClassFunctions.prg
Comment on lines +8 to +28
USING System
USING System.Collections.Generic
USING System.Text
USING XUnit

BEGIN NAMESPACE XSharp.VFP.Tests
CLASS SimpleObj
PROPERTY Name AS STRING AUTO
PROPERTY Age AS INT AUTO
END CLASS

CLASS NestedObj
PROPERTY Title AS STRING AUTO
PROPERTY Child AS SimpleObj AUTO
END CLASS

CLASS ExtraPropObj
PROPERTY Name AS STRING AUTO
PROPERTY Age AS INT AUTO
PROPERTY Extra AS STRING AUTO
END CLASS
Comment thread src/Runtime/XSharp.VFP.Tests/CompObjTests.prg
Comment thread src/Runtime/XSharp.VFP/ClassFunctions.prg Outdated
… check, depth guard, tests

Agent-Logs-Url: https://github.com/X-Sharp/XSharpPublic/sessions/f467ceb6-90a9-4fe4-8b57-737527ffeb28

Co-authored-by: RobertvanderHulst <14240939+RobertvanderHulst@users.noreply.github.com>
Copy link
Copy Markdown
Member

@RobertvanderHulst RobertvanderHulst left a comment

Choose a reason for hiding this comment

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

ok

@RobertvanderHulst RobertvanderHulst merged commit be428ca into dev May 4, 2026
1 of 2 checks passed
@RobertvanderHulst RobertvanderHulst deleted the feature/vfp-compobj branch May 4, 2026 06:23
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.

4 participants