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

record note to ReadMe #1110

Merged
merged 2 commits into from
Nov 12, 2020
Merged

record note to ReadMe #1110

merged 2 commits into from
Nov 12, 2020

Conversation

neuecc
Copy link
Member

@neuecc neuecc commented Nov 11, 2020

C# 9.0 record and primary constructor is already supported MessagePack-CSharp.
But property: notation is slightly tricky, so add note to ReadMe.

Question: @AArnott
Emitted resolver is already supported but mpc(Roslyn) is not.
I've update Microsoft.CodeAnalysis.CSharp to latest, it can collect record type and can get by IPropertySymbol.
However .GetAttributes returns empty if set attribute to primary constructor's parameter(like [property:Key(0)] int X).
Do you know any info?

@neuecc neuecc requested a review from AArnott November 11, 2020 09:07
@@ -150,7 +150,7 @@ async void OnGUI()
invokingMpc = true;
try
{
var log = await ProcessHelper.InvokeProcessStartAsync("dotnet", "mpc " + commnadLineArguments);
var log = await ProcessHelper.InvokeProcessStartAsync("mpc " + commnadLineArguments);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect the compile break problem here is you need to keep two parameter. Maybe split: "mpc", commnadLineArguments

Also maybe fix the typo in commnadLineArguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah sorry, mistake with #1109, I should remove this commit in this PR.

@AArnott
Copy link
Collaborator

AArnott commented Nov 11, 2020

I haven't experimented with Reflection over C# 9 records at all yet. Attributes can be obtained from parameters, but sometimes C# uses attributes that compile out in the IL, instead using some other CLR metadata other than custom attributes. You can check this by using ILSpy to decompile the assembly as IL instead of C# to see how the data you need is actually represented.

@neuecc
Copy link
Member Author

neuecc commented Nov 12, 2020

In Runtime Reflection, a record is represented by {get; init;}, and
init; is converted to {get; [IsExternalInit]set;}, so it was no problem at all.

I don't know how Roslyn(+Compilation) handles this: .......

@neuecc neuecc merged commit ba85be1 into master Nov 12, 2020
@neuecc neuecc deleted the support-record branch November 12, 2020 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants