Runtime: Type: Needs api to distinguish SzArrays from Multidim arrays of rank 1.

Created on 1 Mar 2017  路  10Comments  路  Source: dotnet/runtime

The SZ array type ("T[]") and rank 1 multidim arrays ("T[*]") are distinct and non-interchangable types in .NET. However, the Reflection surface area contains no api to distinguish. (The most "obvious" approach ("t is Array && t.GetArrayRank() == 1") captures both.)

Proposal:

Add a new property to System.Type:
c# public virtual bool IsSZArray { get { throw NotImplemented.ByDesign; }} // Subclass needs to implement
Alternate names that have been proposed:
IsSZArray
IsVector

The name "IsSzArray" has the small advantage that it already exists in both CoreClr and CoreRt - it's just not public.

api-approved area-System.Reflection up-for-grabs

Most helpful comment

I prefer IsSZArrayas the Z being lower case seems strange.

I prefer either capitalisation to IsVector, since vector has a few other meanings, and I think most people who would want to query this property would be familiar with the term sz-array.

All 10 comments

Would it make sense to also add IsMdArray?

I don't know how common the pattern is in reflection, but in the CoreRT type system, we ended up adding such method (dotnet/corert#1925) because it's just easier to read and better captures the intent (as you can see in the PR).

I prefer IsSZArrayas the Z being lower case seems strange.

I prefer either capitalisation to IsVector, since vector has a few other meanings, and I think most people who would want to query this property would be familiar with the term sz-array.

API review: Approved as IsSZArray (with upper case Z to adhere to CoreFX naming rules)

Next step: Needs exposure from CoreCLR/CoreRT, potentially rename in CoreCLR/CoreRT.
Complexity: Medium.

Top post updated to IsSZArray.
@MichalStrehovsky please file a separate issue for IsMDArray - probably as IsMultiDimensionalArray. It seems to make sense.

I can take this one, but not until the weekend, so if someone else wants to jump on it in the meantime, feel free.

Assigning to you @JonHanna ...

Already working on the corert half of this.

@AtsushiKan are you far into the corert? I'd also started on that.

@JonHanna - yes, it's already in review internally and it involves some other followup changes beyond just renaming IsSzArray,

Cool, I'll leave that alone, so.

Was this page helpful?
0 / 5 - 0 ratings