1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

C#: Fix Generated ScriptProperty Error.

1. Add "this." to prevent errors caused by duplicate variable names.
2. Try to find the default value of property getters.
This commit is contained in:
Magian
2022-11-27 17:40:40 +08:00
parent f16c5b564b
commit c41196f0f3
3 changed files with 150 additions and 11 deletions

View File

@@ -12,6 +12,95 @@ namespace Godot.SourceGenerators.Sample
[SuppressMessage("ReSharper", "InconsistentNaming")]
public partial class ExportedProperties : Godot.Object
{
// Do not generate default value
private String _notGenerate_Property_String = new string("not generate");
[Export]
public String NotGenerate_Complex_Lamda_Property
{
get => _notGenerate_Property_String + Convert.ToInt32("1");
set => _notGenerate_Property_String = value;
}
[Export]
public String NotGenerate_Lamda_NoField_Property
{
get => new string("not generate");
set => _notGenerate_Property_String = value;
}
[Export]
public String NotGenerate_Complex_Return_Property
{
get
{
return _notGenerate_Property_String + Convert.ToInt32("1");
}
set
{
_notGenerate_Property_String = value;
}
}
private int _notGenerate_Property_Int = 1;
[Export]
public string NotGenerate_Returns_Property
{
get
{
if (_notGenerate_Property_Int == 1)
{
return "a";
}
else
{
return "b";
}
}
set
{
_notGenerate_Property_Int = value == "a" ? 1 : 2;
}
}
// Full Property
private String _fullProperty_String = "FullProperty_String";
[Export]
public String FullProperty_String
{
get
{
return _fullProperty_String;
}
set
{
_fullProperty_String = value;
}
}
private String _fullProperty_String_Complex = new string("FullProperty_String_Complex") + Convert.ToInt32("1");
[Export]
public String FullProperty_String_Complex
{
get
{
return _fullProperty_String_Complex;
}
set
{
_fullProperty_String_Complex = value;
}
}
// Lamda Property
private String _lamdaProperty_String = "LamdaProperty_String";
[Export]
public String LamdaProperty_String
{
get => _lamdaProperty_String;
set => _lamdaProperty_String = value;
}
// Auto Property
[Export] private Boolean property_Boolean { get; set; } = true;
[Export] private Char property_Char { get; set; } = 'f';
[Export] private SByte property_SByte { get; set; } = 10;