summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-07-28 17:41:50 +0200
committerIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-08-22 03:36:52 +0200
commit3123be2384c14f7dd156b1cc2d53d822002b837a (patch)
tree34358a0c1b1e2555b8df0a5c346e20e4d9ff6645 /modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
parent344f5028d48d4a5caf321abdf023c34f52aae0a4 (diff)
downloadredot-engine-3123be2384c14f7dd156b1cc2d53d822002b837a.tar.gz
C#: Array, Dictionary and marshaling refactoring
- Array and Dictionary now store `Variant` instead of `System.Object`. - Removed generic Array and Dictionary. They cause too much issues, heavily relying on reflection and very limited by the lack of a generic specialization. - Removed support for non-Godot collections. Support for them also relied heavily on reflection for marshaling. Support for them will likely be re-introduced in the future, but it will have to rely on source generators instead of reflection. - Reduced our use of reflection. The remaining usages will be moved to source generators soon. The only usage that I'm not sure yet how to replace is dynamic invocation of delegates.
Diffstat (limited to 'modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs28
1 files changed, 12 insertions, 16 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
index 224a2d0a50..1b87c6e760 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
@@ -160,8 +160,8 @@ namespace Godot.SourceGenerators
source.Append(" info.AddProperty(GodotInternal.PropName_")
.Append(propertyName)
- .Append(", this.")
- .Append(propertyName)
+ .Append(", ")
+ .AppendManagedToVariantExpr(string.Concat("this.", propertyName), property.Type)
.Append(");\n");
}
@@ -173,8 +173,8 @@ namespace Godot.SourceGenerators
source.Append(" info.AddProperty(GodotInternal.PropName_")
.Append(fieldName)
- .Append(", this.")
- .Append(fieldName)
+ .Append(", ")
+ .AppendManagedToVariantExpr(string.Concat("this.", fieldName), field.Type)
.Append(");\n");
}
@@ -202,19 +202,17 @@ namespace Godot.SourceGenerators
foreach (var property in godotClassProperties)
{
string propertyName = property.PropertySymbol.Name;
- string propertyTypeQualifiedName = property.PropertySymbol.Type.FullQualifiedName();
- source.Append(" if (info.TryGetProperty<")
- .Append(propertyTypeQualifiedName)
- .Append(">(GodotInternal.PropName_")
+ source.Append(" if (info.TryGetProperty(GodotInternal.PropName_")
.Append(propertyName)
.Append(", out var _value_")
.Append(propertyName)
.Append("))\n")
.Append(" this.")
.Append(propertyName)
- .Append(" = _value_")
- .Append(propertyName)
+ .Append(" = ")
+ .AppendVariantToManagedExpr(string.Concat("_value_", propertyName),
+ property.PropertySymbol.Type, property.Type)
.Append(";\n");
}
@@ -223,19 +221,17 @@ namespace Godot.SourceGenerators
foreach (var field in godotClassFields)
{
string fieldName = field.FieldSymbol.Name;
- string fieldTypeQualifiedName = field.FieldSymbol.Type.FullQualifiedName();
- source.Append(" if (info.TryGetProperty<")
- .Append(fieldTypeQualifiedName)
- .Append(">(GodotInternal.PropName_")
+ source.Append(" if (info.TryGetProperty(GodotInternal.PropName_")
.Append(fieldName)
.Append(", out var _value_")
.Append(fieldName)
.Append("))\n")
.Append(" this.")
.Append(fieldName)
- .Append(" = _value_")
- .Append(fieldName)
+ .Append(" = ")
+ .AppendVariantToManagedExpr(string.Concat("_value_", fieldName),
+ field.FieldSymbol.Type, field.Type)
.Append(";\n");
}