Skip to content

Comments

Various additions#511

Open
PTKu wants to merge 6 commits intodevfrom
510-various-additions
Open

Various additions#511
PTKu wants to merge 6 commits intodevfrom
510-various-additions

Conversation

@PTKu
Copy link
Contributor

@PTKu PTKu commented Feb 23, 2026

This pull request introduces automatic generation of strongly-typed enum accessor properties for PLC enum-based and named value-based properties in the C# code generated by the AXSharp compiler. It also improves the handling and annotation of these enum properties, updates documentation, and makes minor fixes in pragma parsing and diagnostics.

Typed Enum Accessor Properties and Annotations

  • The AXSharp compiler now automatically generates strongly-typed enum accessor properties (e.g., StatusEnum) for properties based on PLC ENUM types and named value types with integral backing types. These accessors allow direct, type-safe access to enum values without manual casting. [1] [2] [3] [4] [5]
  • All such properties are annotated with [EnumeratorDiscriminatorAttribute] to maintain enum type information for serialization and UI support in both onliner and POCO classes. [1] [2]

Documentation Updates

  • The documentation (ADDED_MEMBERS.md and README.md) has been updated to describe the new typed enum accessor property feature, including usage examples, scenarios, and important notes about reading values. [1] [2]

Pragma Parsing and Diagnostics

  • Improved pragma parsing to handle malformed pragmas gracefully by swallowing exceptions and returning empty strings, preventing crashes during property value retrieval. [1] [2]
  • Fixed diagnostic messages to display correct (1-based) line numbers for pragma errors.
  • Adjusted pragma grammar rule ordering for correct parsing precedence.

Tests and Examples

  • Updated generated test files to include the new enum accessor properties and annotations, ensuring the feature works as intended in various scenarios. [1] [2] [3] [4] [5]

Miscellaneous

  • Added a helper method to detect if a named value type has an integral backing type, ensuring only eligible types get enum accessors.
  • Minor code and comment formatting improvements. [1] [2] [3] [4] [5]

These changes collectively enhance developer ergonomics, type safety, and code clarity when working with PLC enums and named value types in AXSharp-generated C# code.

closes #510
closes #386
closes #455

@PTKu PTKu linked an issue Feb 23, 2026 that may be closed by this pull request
PTKu added 5 commits February 23, 2026 14:30
Emit AXSharp.Connector.EnumeratorDiscriminatorAttribute on generated POCO properties representing enum and named value types. Update CsPlainSourceBuilder to generate this attribute, and regenerate .g.cs files to include it. Bump AXSharp.Abstractions and AXSharp.Connector package versions to support the new attribute. This improves metadata for reflection and tooling.
…ing types for enums; update CsPlainSourceBuilder for global attribute usage.
- Enhance GetPropertyValue to detect and handle malformed pragmas, returning an empty string on error.
- Adjust error messages to use 1-based line numbers for clarity.
- Reorder grammar rules for correct pragma parsing precedence.
- Minor formatting and copyright updates.
Introduced PragmaParserTests covering property, attribute, setter, and generic pragma parsing, as well as error handling and edge cases. Added PragmaMock for IPragma and used NSubstitute for IDeclaration mocking. This significantly improves test coverage and robustness for pragma parsing.
@PTKu PTKu marked this pull request as ready for review February 23, 2026 15:58
@PTKu PTKu requested review from TomKovac and kuh0005 February 23, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant