-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for primary constructors (#210)
Mapping between parameter names and member names only permits exact case-sensitive match, so lower-case parameters will not map automatically.
- Loading branch information
Showing
14 changed files
with
124 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...Test/test_output/DeserializeTests/NoParameterlessOrPrimaryCtor#C.IDeserialize.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//HintName: C.IDeserialize.cs | ||
|
||
#nullable enable | ||
using System; | ||
using Serde; | ||
|
||
partial class C : Serde.IDeserializeProvider<C> | ||
{ | ||
static IDeserialize<C> IDeserializeProvider<C>.DeserializeInstance => CDeserializeProxy.Instance; | ||
|
||
sealed class CDeserializeProxy : Serde.IDeserialize<C> | ||
{ | ||
C Serde.IDeserialize<C>.Deserialize(IDeserializer deserializer) | ||
{ | ||
int _l_a = default !; | ||
byte _r_assignedValid = 0; | ||
var _l_serdeInfo = global::Serde.SerdeInfoProvider.GetInfo<C>(); | ||
var typeDeserialize = deserializer.ReadType(_l_serdeInfo); | ||
int _l_index_; | ||
while ((_l_index_ = typeDeserialize.TryReadIndex(_l_serdeInfo, out _)) != IDeserializeType.EndOfType) | ||
{ | ||
switch (_l_index_) | ||
{ | ||
case 0: | ||
_l_a = typeDeserialize.ReadI32(_l_index_); | ||
_r_assignedValid |= ((byte)1) << 0; | ||
break; | ||
case Serde.IDeserializeType.IndexNotFound: | ||
typeDeserialize.SkipValue(); | ||
break; | ||
default: | ||
throw new InvalidOperationException("Unexpected index: " + _l_index_); | ||
} | ||
} | ||
|
||
var newType = new C(); | ||
return newType; | ||
} | ||
|
||
public static readonly CDeserializeProxy Instance = new(); | ||
private CDeserializeProxy() | ||
{ | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...est_output/DeserializeTests/NoParameterlessOrPrimaryCtor#C.ISerdeInfoProvider.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//HintName: C.ISerdeInfoProvider.cs | ||
|
||
#nullable enable | ||
partial class C : Serde.ISerdeInfoProvider | ||
{ | ||
static global::Serde.ISerdeInfo global::Serde.ISerdeInfoProvider.SerdeInfo { get; } = Serde.SerdeInfo.MakeCustom( | ||
"C", | ||
typeof(C).GetCustomAttributesData(), | ||
new (string, global::Serde.ISerdeInfo, System.Reflection.MemberInfo)[] { | ||
("a", global::Serde.SerdeInfoProvider.GetInfo<global::Serde.Int32Proxy>(), typeof(C).GetField("A")!) | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
...t/test_output/DeserializeTests/NoParameterlessOrPrimaryCtor#FinalDiagnostics.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
{ | ||
"Id": "CS7036", | ||
"Title": "", | ||
"Severity": "Error", | ||
"WarningLevel": "0", | ||
"Location": "SerdeGenerator/Serde.SerdeImplRoslynGenerator/C.IDeserialize.cs: (34,30)-(34,31)", | ||
"HelpLink": "https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS7036)", | ||
"MessageFormat": "There is no argument given that corresponds to the required parameter '{0}' of '{1}'", | ||
"Message": "There is no argument given that corresponds to the required parameter 'A' of 'C.C(int)'", | ||
"Category": "Compiler" | ||
} | ||
] |
14 changes: 14 additions & 0 deletions
14
...de.Generation.Test/test_output/DeserializeTests/NoParameterlessOrPrimaryCtor.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Id: ERR_MissingPrimaryCtor, | ||
Title: , | ||
Severity: Error, | ||
WarningLevel: 0, | ||
Location: : (2,14)-(2,15), | ||
MessageFormat: Type must have either a primary constructor or a parameterless constructor., | ||
Message: Type must have either a primary constructor or a parameterless constructor., | ||
Category: Serde | ||
} | ||
] | ||
} |