Implement COMPOBJ() function#1914
Conversation
There was a problem hiding this comment.
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 underClassFunctions.prg. - Implemented property-based comparison via reflection with recursion for nested objects and special handling for
NULL_OBJECT. - Added a new
CompObjTests.prgtest 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.
| LOCAL oProp2 := NULL AS PropertyInfo | ||
| FOREACH VAR oP IN aProps2 | ||
| IF oP:Name == oProp1:Name | ||
| oProp2 := oP | ||
| EXIT | ||
| ENDIF | ||
| NEXT |
There was a problem hiding this comment.
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.
| 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 |
… 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>
Implements the
COMPOBJ()function.