SDT1308: RML Data Interface Used On Non-Class
| Property | Value |
|---|---|
| Rule ID | SDT1308 |
| Title | RML Data Interface Used On Non-Class |
| Category | UI |
| Severity | Error |
Cause
A non-class type (such as a struct or record struct) implements IRmlDataArray, IRmlDataStruct, or IRmlDataScalar.
Rule Description
RmlUi data binding relies on reference semantics, stable object identities, and in-place property mutations. Value types (struct) are passed by value and boxed when accessed through interfaces, breaking change notification and dirty tracking. Consequently, RML data interfaces may only be implemented on reference types (class).
How to Fix Violations
Convert the struct declaration to a class.
Violation:
public struct HealthDisplay : IRmlDataStruct
{
[RmlDataVariable] public int CurrentHp;
[RmlDataVariable] public int MaxHp;
}
Fix:
public sealed class HealthDisplay : IRmlDataStruct
{
[RmlDataVariable] public int CurrentHp;
[RmlDataVariable] public int MaxHp;
}
When to Suppress Warnings
Danger
Do not suppress this error. Implementing RML data interfaces on structs causes value-copying bugs and binding registration failures at runtime.