Skip to content

Commit

Permalink
Merge pull request #214 from VaclavElias/master
Browse files Browse the repository at this point in the history
feat: Diagnostic example section added with an image
  • Loading branch information
VaclavElias authored Oct 27, 2023
2 parents d79d4dd + 6128dc2 commit 8e68278
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _data/site.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0.21",
"version": "2.0.0.22",
"engine": "Eleventy 2.0",
"title": "Stride Game Engine",
"description": "C# Stride Game Engine is a powerful and versatile game development engine that is based on the C# programming language",
Expand Down
Binary file added images/blog/2023-10/diagnostics-example.webp
Binary file not shown.
30 changes: 30 additions & 0 deletions posts/2023-10-23-new-diagnostic-analyzers-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,38 @@ The new `Diagnostics` primarily focus on [Serialization](https://doc.stride3d.ne

Each error code follows this format: `STRDIAGXXX`, where 'X' represents a numerical digit. Clicking on these error codes will open a help page that explains in depth why the `DiagnosticAnalyzer` was triggered and how to resolve the warning. You can find these error code pages [here](https://doc.stride3d.net/latest/en/diagnostics/).

## Example

In this example, we'll delve into a common scenario where the `DiagnosticAnalyzer` spots issues related to Stride's serialization rules. We have a `Dictionary` property named `Name` within a class `Example`. We've also adorned the `Name` property with `[DataMember]` and `[DataMemberIgnore]` attributes which are contradictory, and this is where the `DiagnosticAnalyzer` steps in to provide valuable feedback.


```csharp
public class Example
{
[DataMember]
[DataMemberIgnore]
public Dictionary<Example, int> Name { private get; set; }
}
```

Upon compiling, the `DiagnosticAnalyzer` flags three diagnostic warnings related to the attributes and the property's accessibility:

```yml
STRDIAG000: There is an Attribute Contradiction on 'Name' Member. [DataMemberIgnore] Attribute on a [DataMember] is not supported. Except if it has also [DataMemberUpdatable] Attribute.
STRDIAG009: The member 'Name' implements IDictionary<T,K> with an unsupported type for the key. Only primitive types ( like int,float,.. ) are supported or string or enums as the Dictionary Key in asset serialization. When used in other contexts the warning may not apply and can be suppressed.
STRDIAG004: The property 'Name' with [DataMember] does not have an accessible getter which is required for serialization. A public/internal/internal protected getter is expected.
```
The following image demonstrates how these warnings are displayed in Visual Studio:
{% img-click 'Diagnostics warning in Visual Studio' '/images/blog/2023-10/diagnostics-example.webp' %}
These warnings provide immediate feedback, aiding the developer in adhering to Stride's serialization rules. The `DiagnosticAnalyzer` not only pinpoints the issues but also suggests the necessary adjustments to align the code with Stride's standards. For instance, it suggests the removal of the `[DataMemberIgnore]` attribute or the addition of a `[DataMemberUpdatable]` attribute to resolve the attribute contradiction on the `Name` member. It also highlights the requirement for an accessible getter for serialization, and informs about the supported types for the `Dictionary` key in asset serialization.

## Why use it?

This real-time feedback is invaluable, making the coding process smoother and less error-prone, and ensuring that the codebase remains compliant with Stride's serialization standards.

This feature aims to minimize those "Why is my property not showing up in the [Game Studio](https://doc.stride3d.net/latest/en/manual/game-studio/index.html)?" moments. It's often unclear why certain properties don't appear in the editor. These analyzers are designed to clarify such situations, aiding your development process in Stride.

## Current State
Expand Down

0 comments on commit 8e68278

Please sign in to comment.