13

I'm currently dealing with reflection in c#. After:

Assembly.LoadFile(@"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Numerics.Vectors.dll").GetTypes()

And i found this: [System.Numerics.Matrix4x4], [System.Numerics.Matrix4x4+CanonicalBasis], [System.Numerics.Matrix4x4+VectorBasis] (There are reflected types from "System.Numerics.Vectors.dll") I know that Matrix4x4 is structture, however I can't find any info about CanonicalBasis and VectorBasis, and what "+" means in this context. I was doing further research and another strange thing is that:

Assembly.LoadFile(@"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Numerics.Vectors.dll").GetType("System.Numerics.Matrix4x4+VectorBasis").FullName
"System.Numerics.Matrix4x4+VectorBasis"

But:

Assembly.LoadFile(@"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Numerics.Vectors.dll").GetType("System.Numerics.Matrix4x4+VectorBasis").Name
"VectorBasis"

Moreover, when I looked through members of Matrix4x4+VectorBasis there is member like this:

[System.Numerics.Vector3* Element0] 

And is it raw pointer like in c++? Or what is it?

P.S. I was doing it in c# interactive, but i don't think it had any influence on results.

adjan
  • 13,371
  • 2
  • 31
  • 48
Kacper
  • 451
  • 6
  • 17

2 Answers2

13

The + between class names means that the part after the + is a nested type of the type which name is before the +. For example Dictionary<string, string>+KeyCollection. KeyCollection is an inner class of Dictionary<TKey, TValue>.

The * denotes a pointer indeed, since the field mentioned is in unsafe mode:

public unsafe Vector3* Element0;
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • However if I do: Assembly.LoadFile(@"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Numerics.Vectors.dll").GetType("System.Numerics.Matrix4x4").GetNestedTypes() I get: Type[0] { } – Kacper May 06 '18 at 14:37
  • @Kacper `GetNestedTypes` only shows you **public** nested types. See my answer – adjan May 06 '18 at 16:40
  • 2
    @Kacper use `GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)` to get *all* the nested types. – Lucas Trzesniewski May 06 '18 at 18:49
  • Is this naming pattern (`+` for nested types) actually defined in the spec, or is it just the current compiler version's convention? – Bradley Uffner May 07 '18 at 17:24
4

In the string System.Numerics.Matrix4x4+VectorBasis, + means that VectorBasis is a nested type of Matrix4x4. In this particular case VectorBasis is a nested struct inside of a class. Note that + is the same symbol not matter what kind of nested type you're dealing with:

class A
{
    public class B {}
}

struct A
{
    public struct B {}
}

class A
{
    public enum B {}  
}

All nested types in these examples have the same FullName, A+B.

In your case, VectorBasis and CanonicalBasis are private members, that's why you can't see them through Type.GetNestedTypes() which only shows public members.


The * after System.Numerics.Vector3* means that it is a pointer type. The string comes from the Type instance of the FieldInfo.FieldType property.


You can look up this and other possible string representations of the Type class on the corresponding page of the MSDN documentation.

adjan
  • 13,371
  • 2
  • 31
  • 48