Skip to content

Commit 127aa60

Browse files
authored
Update serialization.md to clearly indicate that readonly and private members are supported. (#36354)
* Update serialization.md to clearly indicate that `readonly` and `private` members are supported. Fixes #36353 * Fix lint warning
1 parent 0697deb commit 127aa60

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/orleans/host/configuration-guide/serialization.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ public class Book : Publication
7373

7474
In the preceding code, note that both `Publication` and `Book` have members with `[Id(0)]` even though `Book` derives from `Publication`. This is the recommended practice in Orleans because members identifiers are scoped to the inheritance level, not the type as a whole. Members can be added and removed from `Publication` and `Book` independently, but a new base class cannot be inserted into the hierarchy once the application has been deployed without special consideration.
7575

76+
Orleans also supports serializing types with `internal`, `private`, and `readonly` members, such as in this example type:
77+
78+
```csharp
79+
[GenerateSerializer]
80+
public struct MyCustomStruct
81+
{
82+
public MyCustom(int intProperty, int intField)
83+
{
84+
IntProperty = intProperty;
85+
_intField = intField;
86+
}
87+
88+
[Id(0)]
89+
public int IntProperty { get; }
90+
91+
[Id(1)] private readonly int _intField;
92+
public int GetIntField() => _intField;
93+
94+
public override string ToString() => $"{nameof(_intField)}: {_intField}, {nameof(IntProperty)}: {IntProperty}";
95+
}
96+
```
97+
7698
By default, Orleans will serialize your type by encoding its full name. You can override this by adding an <xref:Orleans.AliasAttribute?displayProperty=nameWithType>. Doing so will result in your type being serialized using a name that is resilient to renaming the underlying class or moving it between assemblies. Type aliases are globally scoped, and you cannot have two aliases with the same value in an application. For generic types, the alias value must include the number of generic parameters preceded by a backtick, for example, `MyGenericType<T, U>` could have the alias <code>[Alias("mytype\`2")]</code>.
7799

78100
## Serializing `record` types

0 commit comments

Comments
 (0)