Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Add C# 9.0 record support to serializer (#7108) #7119

Merged
merged 2 commits into from
Jun 21, 2021

Conversation

ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Jun 18, 2021

Backport for 3.5.0

Backport of #7108

@ReubenBond ReubenBond added this to the 3.5.0 milestone Jun 18, 2021
ReubenBond and others added 2 commits June 18, 2021 11:17
Co-authored-by: Oisin Grehan <oisin.grehan@hiloenergie.com>
@ReubenBond ReubenBond force-pushed the backport/7108-csharp-9-records branch from 806afeb to d6e1db4 Compare June 18, 2021 18:40
@ReubenBond
Copy link
Member Author

This PR is contingent on #7121, so that should be merged first

}

[Serializable]
public record ParamVal(int Value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReubenBond Does this mean records have to have the Serializable attribute?

Copy link
Member Author

@ReubenBond ReubenBond Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same rules apply for records as for other types: they don't need [Serializable] if they directly appear in another serializable type or a grain interface method signature. I'd recommend adding [Serializable] to any serializable type, though, since that is a more explicit way of telling the code generator to generate a serializer for a type.

ReubenBond added a commit that referenced this pull request Sep 22, 2021
* Upgrade SDK & fix projects

* Add C# 9 record support to serializer (#7108)

Co-authored-by: Oisin Grehan <oisin.grehan@hiloenergie.com>

Co-authored-by: Oisin Grehan <oisin.grehan@hiloenergie.com>
@akourbat
Copy link

Does one still have to use Immutable<T> to tell the runtime not to deep-copy the object or for record types it is not necessary anymore (records are immutable by design)?

@ReubenBond
Copy link
Member Author

Does one still have to use Immutable<T> to tell the runtime not to deep-copy the object or for record types it is not necessary anymore (records are immutable by design)?

Records aren't necessarily immutable. They can have mutable fields or fields of mutable types (dictionary, list, etc).

Note that you can annotate a type with [Immutable] instead of wrapping it with Immutable<T> if you prefer

@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants