Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Untyped to typed ArgumentNullException #83051

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public Array()
/// <summary>
/// Constructs a new <see cref="Array"/> from the given collection's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="collection"/> is <see langword="null"/>.
/// </exception>
/// <param name="collection">The collection of elements to construct from.</param>
/// <returns>A new Godot Array.</returns>
public Array(IEnumerable<Variant> collection) : this()
Expand All @@ -50,6 +53,9 @@ public Array(IEnumerable<Variant> collection) : this()
/// <summary>
/// Constructs a new <see cref="Array"/> from the given objects.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <param name="array">The objects to put in the new array.</param>
/// <returns>A new Godot Array.</returns>
public Array(Variant[] array)
Expand All @@ -68,6 +74,13 @@ public Array(Variant[] array)
this[i] = array[i];
}

/// <summary>
/// Constructs a new <see cref="Array"/> from the given span's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <returns>A new Godot Array.</returns>
public Array(Span<StringName> array)
{
if (array == null)
Expand All @@ -84,6 +97,13 @@ public Array(Span<StringName> array)
this[i] = array[i];
}

/// <summary>
/// Constructs a new <see cref="Array"/> from the given span's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <returns>A new Godot Array.</returns>
public Array(Span<NodePath> array)
{
if (array == null)
Expand All @@ -100,6 +120,13 @@ public Array(Span<NodePath> array)
this[i] = array[i];
}

/// <summary>
/// Constructs a new <see cref="Array"/> from the given span's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <returns>A new Godot Array.</returns>
public Array(Span<Rid> array)
{
if (array == null)
Expand All @@ -121,6 +148,13 @@ public Array(Span<Rid> array)
// fine as long as the array is not mutated. However, Span does this type checking at
// instantiation, so it's not possible to use it even when not mutating anything.
// ReSharper disable once RedundantNameQualifier
/// <summary>
/// Constructs a new <see cref="Array"/> from the given ReadOnlySpan's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <returns>A new Godot Array.</returns>
public Array(ReadOnlySpan<GodotObject> array)
{
if (array == null)
Expand Down Expand Up @@ -861,9 +895,15 @@ public void MakeReadOnly()
/// Copies the elements of this <see cref="Array"/> to the given
/// <see cref="Variant"/> C# array, starting at the given index.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="arrayIndex"/> is less than 0 or greater than the array's size.
/// </exception>
/// <exception cref="ArgumentException">
/// The destination array was not long enough.
/// </exception>
/// <param name="array">The array to copy to.</param>
/// <param name="arrayIndex">The index to start at.</param>
public void CopyTo(Variant[] array, int arrayIndex)
Expand Down Expand Up @@ -1031,6 +1071,7 @@ internal ref godot_array.movable NativeValue
/// <summary>
/// Constructs a new empty <see cref="Array{T}"/>.
/// </summary>
/// <returns>A new Godot Array.</returns>
public Array()
{
_underlyingArray = new Array();
Expand All @@ -1039,6 +1080,9 @@ public Array()
/// <summary>
/// Constructs a new <see cref="Array{T}"/> from the given collection's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="collection"/> is <see langword="null"/>.
/// </exception>
/// <param name="collection">The collection of elements to construct from.</param>
/// <returns>A new Godot Array.</returns>
public Array(IEnumerable<T> collection)
Expand All @@ -1055,6 +1099,9 @@ public Array(IEnumerable<T> collection)
/// <summary>
/// Constructs a new <see cref="Array{T}"/> from the given items.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <param name="array">The items to put in the new array.</param>
/// <returns>A new Godot Array.</returns>
public Array(T[] array)
Expand All @@ -1071,9 +1118,16 @@ public Array(T[] array)
/// <summary>
/// Constructs a typed <see cref="Array{T}"/> from an untyped <see cref="Array"/>.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <param name="array">The untyped array to construct from.</param>
/// <returns>A new Godot Array.</returns>
public Array(Array array)
{
if (array == null)
throw new ArgumentNullException(nameof(array));

_underlyingArray = array;
}

Expand All @@ -1085,6 +1139,7 @@ internal static Array<T> CreateTakingOwnershipOfDisposableValue(godot_array nati
/// Converts this typed <see cref="Array{T}"/> to an untyped <see cref="Array"/>.
/// </summary>
/// <param name="from">The typed array to convert.</param>
/// <returns>A new Godot Array, or <see langword="null"/> if <see paramref="from"/> was null.</returns>
public static explicit operator Array(Array<T> from)
{
return from?._underlyingArray;
Expand Down Expand Up @@ -1695,9 +1750,15 @@ public void Clear()
/// Copies the elements of this <see cref="Array{T}"/> to the given
/// C# array, starting at the given index.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="arrayIndex"/> is less than 0 or greater than the array's size.
/// </exception>
/// <exception cref="ArgumentException">
/// The destination array was not long enough.
/// </exception>
/// <param name="array">The C# array to copy to.</param>
/// <param name="arrayIndex">The index to start at.</param>
public void CopyTo(T[] array, int arrayIndex)
Expand Down
34 changes: 34 additions & 0 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ public bool TryGetValue(Variant key, out Variant value)
/// Copies the elements of this <see cref="Dictionary"/> to the given untyped
/// <see cref="KeyValuePair{TKey, TValue}"/> array, starting at the given index.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="arrayIndex"/> is less than 0 or greater than the array's size.
/// </exception>
/// <exception cref="ArgumentException">
/// The destination array was not long enough.
/// </exception>
/// <param name="array">The array to copy to.</param>
/// <param name="arrayIndex">The index to start at.</param>
void ICollection<KeyValuePair<Variant, Variant>>.CopyTo(KeyValuePair<Variant, Variant>[] array, int arrayIndex)
Expand Down Expand Up @@ -499,6 +508,7 @@ internal ref godot_dictionary.movable NativeValue
/// <summary>
/// Constructs a new empty <see cref="Dictionary{TKey, TValue}"/>.
/// </summary>
/// <returns>A new Godot Dictionary.</returns>
public Dictionary()
{
_underlyingDict = new Dictionary();
Expand All @@ -507,6 +517,9 @@ public Dictionary()
/// <summary>
/// Constructs a new <see cref="Dictionary{TKey, TValue}"/> from the given dictionary's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="dictionary"/> is <see langword="null"/>.
/// </exception>
/// <param name="dictionary">The dictionary to construct from.</param>
/// <returns>A new Godot Dictionary.</returns>
public Dictionary(IDictionary<TKey, TValue> dictionary)
Expand All @@ -523,10 +536,16 @@ public Dictionary(IDictionary<TKey, TValue> dictionary)
/// <summary>
/// Constructs a new <see cref="Dictionary{TKey, TValue}"/> from the given dictionary's elements.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="dictionary"/> is <see langword="null"/>.
/// </exception>
/// <param name="dictionary">The dictionary to construct from.</param>
/// <returns>A new Godot Dictionary.</returns>
public Dictionary(Dictionary dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

_underlyingDict = dictionary;
}

Expand All @@ -539,6 +558,7 @@ internal static Dictionary<TKey, TValue> CreateTakingOwnershipOfDisposableValue(
/// Converts this typed <see cref="Dictionary{TKey, TValue}"/> to an untyped <see cref="Dictionary"/>.
/// </summary>
/// <param name="from">The typed dictionary to convert.</param>
/// <returns>A new Godot Dictionary, or <see langword="null"/> if <see paramref="from"/> was null.</returns>
public static explicit operator Dictionary(Dictionary<TKey, TValue> from)
{
return from?._underlyingDict;
Expand All @@ -555,6 +575,8 @@ public static explicit operator Dictionary(Dictionary<TKey, TValue> from)
/// elements will be shallow copied regardless of the <paramref name="deep"/>
/// setting.
/// </summary>
/// <param name="deep">If <see langword="true"/>, performs a deep copy.</param>
/// <returns>A new Godot Dictionary.</returns>
public Dictionary<TKey, TValue> Duplicate(bool deep = false)
{
return new Dictionary<TKey, TValue>(_underlyingDict.Duplicate(deep));
Expand Down Expand Up @@ -688,6 +710,9 @@ private KeyValuePair<TKey, TValue> GetKeyValuePair(int index)
/// <exception cref="InvalidOperationException">
/// The dictionary is read-only.
/// </exception>
/// <exception cref="ArgumentException">
/// An element with the same <paramref name="key"/> already exists.
/// </exception>
/// <param name="key">The key at which to add the object.</param>
/// <param name="value">The object to add.</param>
public void Add(TKey key, TValue value)
Expand Down Expand Up @@ -810,6 +835,15 @@ bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue>
/// Copies the elements of this <see cref="Dictionary{TKey, TValue}"/> to the given
/// untyped C# array, starting at the given index.
/// </summary>
/// <exception cref="ArgumentNullException">
/// The <paramref name="array"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="arrayIndex"/> is less than 0 or greater than the array's size.
/// </exception>
/// <exception cref="ArgumentException">
/// The destination array was not long enough.
/// </exception>
/// <param name="array">The array to copy to.</param>
/// <param name="arrayIndex">The index to start at.</param>
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Expand Down
Loading