diff --git a/VYaml.SourceGenerator.Roslyn3/VYamlSourceGenerator.cs b/VYaml.SourceGenerator.Roslyn3/VYamlSourceGenerator.cs index dbfb8a8..727da70 100644 --- a/VYaml.SourceGenerator.Roslyn3/VYamlSourceGenerator.cs +++ b/VYaml.SourceGenerator.Roslyn3/VYamlSourceGenerator.cs @@ -427,7 +427,26 @@ static bool TryEmitDeserializeMethod( codeWriter.AppendLine(); foreach (var memberMeta in typeMeta.MemberMetas) { - codeWriter.AppendLine($"var __{memberMeta.Name}__ = default({memberMeta.FullTypeName});"); + codeWriter.Append($"var __{memberMeta.Name}__ = "); + if (memberMeta.HasExplicitDefaultValueFromConstructor) + { + switch (memberMeta.ExplicitDefaultValueFromConstructor) + { + case null: + codeWriter.AppendLine("null;", false); + break; + case string stringValue: + codeWriter.AppendLine($"\"{stringValue}\";", false); + break; + case {} anyValue: + codeWriter.AppendLine($"{anyValue};", false); + break; + } + } + else + { + codeWriter.AppendLine($"default({memberMeta.FullTypeName});", false); + } } using (codeWriter.BeginBlockScope("while (!parser.End && parser.CurrentEventType != ParseEventType.MappingEnd)")) @@ -639,4 +658,4 @@ static bool TryGetConstructor( constructedMembers = parameterMembers; return !error; } -} +} \ No newline at end of file diff --git a/VYaml.Unity/Assets/VYaml/Runtime/VYaml.SourceGenerator.Roslyn3.dll b/VYaml.Unity/Assets/VYaml/Runtime/VYaml.SourceGenerator.Roslyn3.dll index a59fbb2..90abdad 100644 Binary files a/VYaml.Unity/Assets/VYaml/Runtime/VYaml.SourceGenerator.Roslyn3.dll and b/VYaml.Unity/Assets/VYaml/Runtime/VYaml.SourceGenerator.Roslyn3.dll differ