Back to Devexpress

XAF0020: Avoid applying NonPersistentAttribute to properties without a public setter

expressappframework-404101-debugging-testing-and-error-handling-code-diagnostics-xaf0020.md

latest1.1 KB
Original Source

XAF0020: Avoid applying NonPersistentAttribute to properties without a public setter

  • Sep 06, 2022

Severity: Warning

The NonPersistentAttribute is redundant for read-only properties (non-public or missing setters). Apply the attribute only to writeable properties if you do not want their values to persist in a data store.

Examples

Invalid Code

csharp
[NonPersistent]
public Topic Topic {
     get { return fTopic; }
}
Topic fTopic;

// OR

[NonPersistent]
public Topic Topic {
    get { return fTopic; }
    private set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}
Topic fTopic;

Valid Code

csharp
public Topic Topic {
    get { return fTopic; }
}
Topic fTopic;

// OR

public Topic Topic {
    get { return fTopic; }
    private set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}

// OR

[NonPersistent]
public AnyType Topic {
    get { return fTopic; }
    set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}
AnyType fTopic;