C#, Reflection and primitive types

c#, primitive-types, reflection

Solution

This is a duplicate to

C# - Get user-friendly name of simple types through reflection?

This is a good answer by Skeet, too

How can I get the primitive name of a type in C#?

The answer is, YOU CAN, and without a dictionary.

Type t = typeof(bool);

string typeName;
using (var provider = new CSharpCodeProvider())
{
  var typeRef = new CodeTypeReference(t);
  typeName = provider.GetTypeOutput(typeRef);
}

Console.WriteLine(typeName);    // bool

Problem

Possible Duplicate: How can I get the primitive name of a type in C#? I have the following code in C#: ``` Assembly sysAssembly = 0.GetType().Assembly; Type[] sysTypes = sysAssembly.GetTypes(); foreach (Type sysType in sysTypes) { if (sysType.IsPrimitive && sysType.IsPublic) Console.WriteLine(sysType.Name); } ``` This code outputs: Boolean, Byte, Char, Double, Int16, Int32, Int64, IntPtr, SByte, Single, UInt16, UInt32, UInt64, UIntPtr, I would like to replace `Boolean` by `bool`, `Byte` by `byte` and so on when possible, without relying on a fixed array or dictionary. Is there a way to do this?

Original source

Related problems