Support parameter-less event methods in `DataContractSerializer` (without a `StreamingContext` parameter)

Open
#109,264 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
backend

Research direction

Start by locating DataContractSerializer's handling of the four serialization callback attributes and the tests covering StreamingContext parameters. Determine how parameter-less callbacks should coexist with the existing overloads; done means parameter-less methods are supported without breaking compatibility with callbacks that accept StreamingContext.

Written by the indexing model from the issue text.

Description

area-Serialization binaryformatter-migration

When I use event methods for the DataContractSerializer system, I still need a StreamingContext parameter even though the BinaryFormatter stuff is deprecated. The constructor and state property of StreamingContext is marked as obsolete.

The StreamingContext _ parameter is unused in the below code. I feel it is redundant.

[OnSerializing()]
void OnSerializing(StreamingContext _) { ... }

[OnSerialized()]
void OnSerializing(StreamingContext _) { ... }

[OnDeserializing()]
void OnSerializing(StreamingContext _) { ... }

[OnDeserialized()]
void OnSerializing(StreamingContext _) { ... }

Parameter-less one like the code below makes me feel refreshed. Also, we do not need to type unused parameters. So, developing efficiency is more improved. In addition, maybe, passing (copying structure data) the parameter makes a program slow. Or maybe, the speed is the same because of checking parameters.

[OnSerializing()]
void OnSerializing() { ... }

[OnSerialized()]
void OnSerializing() { ... }

[OnDeserializing()]
void OnSerializing() { ... }

[OnDeserialized()]
void OnSerializing() { ... }

I agree that we should still support with StreamingContext _ parameter for compatibility but I want a parameter-less option.

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.