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

Remove dependency on Type.IsSerializable from OptionSet serialization #54990

Merged
merged 1 commit into from
Jul 20, 2021

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 20, 2021

Previous code depended on both sides of the OOP communication channel agreeing on what types are serializable or not. new code does not.

@@ -439,11 +398,9 @@ static bool TryDeserializeOptionKey(ObjectReader reader, ILookup<string, IOption

private enum OptionValueKind
{
Null,
Copy link
Member Author

Choose a reason for hiding this comment

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

Null and String and Serializable were merged into a single item called 'Object'


var kind = OptionValueKind.Null;
object? valueToWrite = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

no need to specially handle 'null', the default case below handles it.

Copy link
Member Author

Choose a reason for hiding this comment

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

also, no need for 'valueToWrite'. we always just write out the literal value.

@@ -215,57 +215,28 @@ public void Serialize(ObjectWriter writer, CancellationToken cancellationToken)
Debug.Assert(ShouldSerialize(optionKey));
Copy link
Member Author

Choose a reason for hiding this comment

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

should view with whitespace off.

if (type.IsEnum)
{
kind = OptionValueKind.Enum;
valueToWrite = (int)value;
Copy link
Member Author

Choose a reason for hiding this comment

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

this cast isn't necessary here due to teh line where we actually write the enum doing this already.

@@ -386,10 +350,6 @@ public static SerializableOptionSet Deserialize(ObjectReader reader, IOptionServ
optionValue = Enum.ToObject(optionKey.Option.Type, readValue);
break;

case OptionValueKind.Null:
optionValue = null;
break;
Copy link
Member Author

Choose a reason for hiding this comment

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

no need for this. already handled by the object reading code.

}

case ICodeStyleOption:
if (optionKey.Option.Type.GenericTypeArguments.Length != 1)
continue;
Copy link
Member

@tmat tmat Jul 20, 2021

Choose a reason for hiding this comment

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

We just ignore options without single generic type param? Shouldn't this throw or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

i am adding this to the list of things to try out in my followup PR :) but yes. seems insane.

@CyrusNajmabadi CyrusNajmabadi requested a review from tmat July 20, 2021 20:58
Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 87f1664 into dotnet:main Jul 20, 2021
@ghost ghost added this to the Next milestone Jul 20, 2021
@CyrusNajmabadi CyrusNajmabadi deleted the optionSetSerialization branch July 21, 2021 02:50
@allisonchou allisonchou modified the milestones: Next, 17.0.P3 Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants