mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-30 21:21:10 +00:00 
			
		
		
		
	C#: Replace most conversions between Variant and System.Object
This commit replaces most usages of `ConvertManagedObjectToVariant` and `ConvertVariantToManagedObjectOfType`, by using the `Godot.Variant` struct instead of `System.Object`. The most notable change is to the `GetGodotPropertyDefaultValues` method that's generated for scripts. The dictionary it returns now stores `Godot.Variant` values. Remaining usages are: - The `DelegateUtils` class, for the serialization of closure display classes during assembly reloading by the editor. These display classes are compiler generated classes to store values captured by a closure. Since it's generated by the compiler, the only way we have to access the fields is through reflection. This leads to using `System.Object`. - Converting parameters when invoking constructors from the engine. This will be replaced with source generators in the future. - Legacy support for old `GetGodotPropertyDefaultValues` return values. We need to keep supporting the old version of this generated method for some time. Otherwise, if loading a project built with the previous version, it could lead to the loss of exported property values. Ideally, we should remove this legacy support before a stable release.
This commit is contained in:
		
							parent
							
								
									3afeb28560
								
							
						
					
					
						commit
						f86c6b6ac4
					
				
					 8 changed files with 350 additions and 443 deletions
				
			
		|  | @ -368,7 +368,7 @@ namespace Godot.SourceGenerators | |||
|                     source.Append(VariantUtils, ".ConvertToSignalInfo(", inputExpr, ")"), | ||||
|                 MarshalType.Enum => | ||||
|                     source.Append("(", typeSymbol.FullQualifiedNameIncludeGlobal(), | ||||
|                         ")", VariantUtils, ".ConvertToInt32(", inputExpr, ")"), | ||||
|                         ")", VariantUtils, ".ConvertToInt64(", inputExpr, ")"), | ||||
|                 MarshalType.ByteArray => | ||||
|                     source.Append(VariantUtils, ".ConvertAsPackedByteArrayToSystemArray(", inputExpr, ")"), | ||||
|                 MarshalType.Int32Array => | ||||
|  | @ -491,7 +491,7 @@ namespace Godot.SourceGenerators | |||
|                 MarshalType.SignalInfo => | ||||
|                     source.Append(VariantUtils, ".CreateFromSignalInfo(", inputExpr, ")"), | ||||
|                 MarshalType.Enum => | ||||
|                     source.Append(VariantUtils, ".CreateFromInt((int)", inputExpr, ")"), | ||||
|                     source.Append(VariantUtils, ".CreateFromInt((long)", inputExpr, ")"), | ||||
|                 MarshalType.ByteArray => | ||||
|                     source.Append(VariantUtils, ".CreateFromPackedByteArray(", inputExpr, ")"), | ||||
|                 MarshalType.Int32Array => | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ignacio Roldán Etcheverry
						Ignacio Roldán Etcheverry