Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "+" mean in reflected FullName and '*' after Member c#

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.

like image 635
Kacper Avatar asked May 06 '18 11:05

Kacper


People also ask

What is reflection in C?

Reflection provides objects (of type Type) that describe assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties.

Is reflection slow C#?

Reflection is not THAT slow. Invoking a method by reflection is about 3 times slower than the normal way. That is no problem if you do this just once or in non-critical situations. If you use it 10'000 times in a time-critical method, I would consider to change the implementation.

What is System reflection?

Reflection is the process of describing the metadata of types, methods and fields in a code. The namespace System.Reflection enables you to obtain data about the loaded assemblies, the elements within them like classes, methods and value types. Some of the commonly used classes of System.Reflection are: Class.

What is Java reflection?

Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.


2 Answers

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;
like image 83
Patrick Hofman Avatar answered Oct 20 '22 01:10

Patrick Hofman


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.

like image 42
adjan Avatar answered Oct 19 '22 23:10

adjan