Get all .net available type in system namespace

Is there a function or by using reflection a way to get all the System types.

Like those: - System.Int64

  • System.Byte[]

  • System.Boolean

  • System.String

  • System.Decimal

  • System.Double

  • ...

We have an old enum that stores some datatype. We need to convert those to .net types.

Jon Skeet
people
quotationmark

Assuming you only want types from mscorlib, it's easy:

var mscorlib = typeof(string).Assembly;
var types = mscorlib.GetTypes()
                    .Where(t => t.Namespace == "System");

However, that won't return byte[], as that's an array type. It also won't return types in different assemblies. If you have multiple assemblies you're interested in, you could use:

var assemblies = ...;
var types = assemblies.SelectMany(a => a.GetTypes())
                      .Where(t => t.Namespace == "System");

people

See more on this question at Stackoverflow