|
@@ -1,54 +1,65 @@
|
|
|
-# Diagnostics Warning STRD004
|
|
|
|
|
|
|
+# Diagnostics Warning STRDIAG005
|
|
|
|
|
|
|
|
-For \<see cref="System.Collections.Generic.Dictionary{TKey, TValue}"/> the only valid Keys are primitive Types. All complex types like custom structs, objects are not allowed.
|
|
|
|
|
|
|
+1. The property '{0}' with \[DataMember] does not have a getter which is required for serialization.
|
|
|
|
|
+2. The property '{0}' with \[DataMember] does not have an accessible getter which is required for serialization. A public/internal/internal protected getter is expected.
|
|
|
|
|
+
|
|
|
|
|
+## Explanation
|
|
|
|
|
+
|
|
|
|
|
+All Serializers need a getter on a property to be able to get the content of the property.
|
|
|
|
|
+This is required for all Serializers in Stride.
|
|
|
|
|
+Non existent getters will result in error message 1.
|
|
|
|
|
+Non visible getters will result in error message 2.
|
|
|
|
|
|
|
|
## Example
|
|
## Example
|
|
|
|
|
|
|
|
-The following example generates STRD001:
|
|
|
|
|
|
|
+The following example generates STRDIAG005 on each property:
|
|
|
|
|
|
|
|
```csharp
|
|
```csharp
|
|
|
-// STRD001.cs
|
|
|
|
|
-// compile with: /W:2
|
|
|
|
|
-public class Program
|
|
|
|
|
|
|
+using Stride.Core;
|
|
|
|
|
+
|
|
|
|
|
+public class STRDIAG005
|
|
|
{
|
|
{
|
|
|
- public static void Main()
|
|
|
|
|
- {
|
|
|
|
|
- goto lab1;
|
|
|
|
|
- {
|
|
|
|
|
- // The following statements cannot be reached:
|
|
|
|
|
- int i = 9; // STRD001
|
|
|
|
|
- i++;
|
|
|
|
|
- }
|
|
|
|
|
- lab1:
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ // throws Diagnostics message 1
|
|
|
|
|
+ [DataMember]
|
|
|
|
|
+ public int Value { set;}
|
|
|
|
|
+
|
|
|
|
|
+ // throws Diagnostics message 2
|
|
|
|
|
+ [DataMember]
|
|
|
|
|
+ public string Value { private get; set; }
|
|
|
|
|
|
|
|
|
|
+ // throws Diagnostics message 2
|
|
|
|
|
+ [DataMember]
|
|
|
|
|
+ public string Value { protected get; set; }
|
|
|
|
|
+}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-Another common example where this error is generated is as follows:
|
|
|
|
|
|
|
+There is an edge case with internal/internal protected, it will count as non visible when the [DataMember] Attribute isn't applied.
|
|
|
|
|
+But when the Attribute is applied then the getter counts as visible and therfore is correct.
|
|
|
|
|
|
|
|
```csharp
|
|
```csharp
|
|
|
-public static class Class1
|
|
|
|
|
|
|
+// STRDIAG000.cs
|
|
|
|
|
+using Stride.Core;
|
|
|
|
|
+
|
|
|
|
|
+public class STRDIAG004
|
|
|
{
|
|
{
|
|
|
- public static string Method1()
|
|
|
|
|
- {
|
|
|
|
|
- string x = "a";
|
|
|
|
|
- switch (x)
|
|
|
|
|
- {
|
|
|
|
|
- case "a":
|
|
|
|
|
- return "a";
|
|
|
|
|
- break; // CS0162
|
|
|
|
|
- }
|
|
|
|
|
- return "";
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // will throw STRDIAG004
|
|
|
|
|
+ public int Value { internal get; set;}
|
|
|
|
|
+
|
|
|
|
|
+ // will throw STRDIAG004
|
|
|
|
|
+ public int Value { internal protected get; set;}
|
|
|
|
|
+
|
|
|
|
|
+ // won't throw STRDIAG004
|
|
|
|
|
+ [DataMember]
|
|
|
|
|
+ public string Value { internal get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ // won't throw STRDIAG004
|
|
|
|
|
+ [DataMember]
|
|
|
|
|
+ public string Value { internal protected get; set; }
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-The `break` statement cannot be reached because it occurs after the `return` statement. The `return` statement ends the enclosing `case` branch.
|
|
|
|
|
|
|
+## Solution
|
|
|
|
|
|
|
|
-## See also
|
|
|
|
|
|
|
+To resolve the warning 1, add a getter to the property with a public/internal/internal protected Accessibility or remove the \[DataMember] Attribute.
|
|
|
|
|
|
|
|
-- [C# Compiler Options](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/)
|
|
|
|
|
-- [C# Compiler Errors](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/)
|
|
|
|
|
|
|
+To resolve the warning 2, increase the Accessibility of the property getter to public/internal/internal protected Accessibility or remove the \[DataMember] Attribute.
|