Merge pull request #77743 from raulsntos/dotnet/docs-contains-key

C#: Fix dictionary key lookup documentation
This commit is contained in:
Yuri Sizov 2023-06-02 12:29:06 +02:00 committed by GitHub
commit e683986b24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View file

@ -41,7 +41,7 @@
{
// Check position if it is relevant to you
// Otherwise, just check data
return data.VariantType == Variant.Type.Dictionary && data.AsGodotDictionary().Contains("expected");
return data.VariantType == Variant.Type.Dictionary && data.AsGodotDictionary().ContainsKey("expected");
}
[/csharp]
[/codeblocks]
@ -64,7 +64,7 @@
[csharp]
public override bool _CanDropData(Vector2 atPosition, Variant data)
{
return data.VariantType == Variant.Type.Dictionary && dict.AsGodotDictionary().Contains("color");
return data.VariantType == Variant.Type.Dictionary && dict.AsGodotDictionary().ContainsKey("color");
}
public override void _DropData(Vector2 atPosition, Variant data)

View file

@ -217,9 +217,9 @@
{ 210, default },
};
GD.Print(myDict.Contains("Godot")); // Prints true
GD.Print(myDict.Contains(210)); // Prints true
GD.Print(myDict.Contains(4)); // Prints false
GD.Print(myDict.ContainsKey("Godot")); // Prints true
GD.Print(myDict.ContainsKey(210)); // Prints true
GD.Print(myDict.ContainsKey(4)); // Prints false
[/csharp]
[/codeblocks]
In GDScript, this is equivalent to the [code]in[/code] operator:

View file

@ -93,7 +93,7 @@
new Godot.Collections.Dictionary
{
{ "name", "myOption" },
{ "defaultValue", false },
{ "default_value", false },
}
};
}
@ -157,12 +157,12 @@
return true
[/gdscript]
[csharp]
public void GetOptionVisibility(string option, Godot.Collections.Dictionary options)
public void _GetOptionVisibility(string option, Godot.Collections.Dictionary options)
{
// Only show the lossy quality setting if the compression mode is set to "Lossy".
if (option == "compress/lossyQuality" && options.Contains("compress/mode"))
if (option == "compress/lossy_quality" && options.ContainsKey("compress/mode"))
{
return (int)options["compress/mode"] == COMPRESS_LOSSY; // This is a constant you set
return (int)options["compress/mode"] == CompressLossy; // This is a constant you set
}
return true;