-
-
Notifications
You must be signed in to change notification settings - Fork 510
Description
Please add support for the init property accessor with the required modifier in YamlDotNet Source Generation for AOT
E.g. for a given POCO that I want to map YAML to:
public sealed record BooleanResult
{
public required bool result { get; init; }
}
the generated source code in YamlDotNetAutoGraph.g.cs tries to write to the property but the property has the init accessor instead of the set accessor so a compliation error occurs:
Init-only property or indexer 'BooleanResult.result' can only be assigned in an object initializer, or on 'this' or 'base' in an instance constructor or an 'init' accessor.
// from YamlDotNetAutoGraph.g.cs
switch (propertyName)
{
case "result": v.result = (System.Boolean)value; return;
default: throw new ArgumentOutOfRangeException("propertyName", $"{propertyName} does not exist or is not settable");
}
equally because the required modifier is used all properties must be set when the constructor is called else a compliation error occurs:
Required member 'BooleanResult.result' must be set in the object initializer or attribute constructor.
// from YamlDotNetAutoGraph.g.cs
class StaticObjectFactory : YamlDotNet.Serialization.ObjectFactories.StaticObjectFactory
{
public override object Create(Type type)
{
if (type == typeof(MyNamespace.BooleanResult)) return new MyNamespace.BooleanResult();