hadashiA/VYaml

Type error when using constructor initialization

MonoLogueChi opened this issue · 4 comments

eg

[YamlObject]
public partial class MyClass
{
  public MyClass(int a = 0, float b = 0f)
  {
    A = a;
    B = b;
  }
  public int A { get; set; }
  public float B { get; set; }
}

will generate

var __A__ = 0;
var __B__ = 0;

The type of B should be float, not int

This method may solve the problem, but I'm not familiar with SourceGenerator and I'm not sure if this is correct.

codeWriter.Append($"var __{memberMeta.Name}__ = ");

- codeWriter.Append($"var __{memberMeta.Name}__ = ");
+ codeWriter.Append($"{memberMeta.FullTypeName} __{memberMeta.Name}__ = ");

Enum also has the same problem and will be defined as int type

it would be better to generate it like so

var __TEMP__T= default(double);
var __TEMP__X= default(int);

this code is allready used to generate the temp vars in deserialize

Thanks for the report.
Fixed in #102.