Skip to content

Commit cf7ca6e

Browse files
committed
feat: Made the InheritsAttribute constructor accept null arrays
1 parent fd184c2 commit cf7ca6e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Runtime/Attributes/InheritsAttribute.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ public class InheritsAttribute : TypeOptionsAttribute
2323
/// Additional types the selectable types must inherit from (e.g. multiple interfaces).
2424
/// </param>
2525
[PublicAPI]
26-
public InheritsAttribute(Type baseType, params Type[] additionalBaseTypes)
26+
public InheritsAttribute(Type baseType, [CanBeNull] params Type[] additionalBaseTypes)
2727
{
28-
int additionalTypesLength = additionalBaseTypes.Length;
29-
_baseTypes = new Type[additionalTypesLength+1];
30-
31-
for (int i = 0; i < additionalTypesLength; i++)
32-
_baseTypes[i] = additionalBaseTypes[i];
33-
34-
_baseTypes[additionalTypesLength] = baseType;
28+
if (additionalBaseTypes == null || additionalBaseTypes.Length == 0)
29+
{
30+
_baseTypes = new[] { baseType };
31+
}
32+
else
33+
{
34+
_baseTypes = new Type[additionalBaseTypes.Length+1];
35+
additionalBaseTypes.CopyTo(_baseTypes, 0);
36+
_baseTypes[additionalBaseTypes.Length] = baseType;
37+
}
3538
}
3639

3740
/// <summary>

0 commit comments

Comments
 (0)