0

I have a class

namespace MyNamespace1
{
    class MyClass
    {
        public string MyName { get; set; }
        public int? MaxHeaderLength { get; set; }
        public System.Collections.Generic.List<MyClass.ViewModel> Preferences { get; set; }
    }
}

namespace MyNamespace2
{
    internal class myClass1
    {
        public static void Main(string[] args)
        {
            var properties = loading assembly of the MyClass of MyNamespace1
            var prop = properties.GetProperties();
            foreach (var propertyInfo in prop)
            {
                Console.WriteLine(propertyInfo.PropertyType.FullName);

            }
        }
    }
}

When I want to read the property at the runtime using reflection

I am getting types as

System.String,

System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],

System.Collections.Generic.List`1[[System.Web.Mvc.SelectListItem, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]),

But I want to retrieve as

string,

int?,

System.Collections.Generic.List<MyClass.ViewModel>

Can anybody please provide me the solution.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3458700
  • 27
  • 1
  • 6
  • 1
    You want the *friendly name*. Check http://stackoverflow.com/questions/16466380/get-user-friendly-name-for-generic-type-in-c-sharp and http://stackoverflow.com/questions/4615553/c-sharp-get-user-friendly-name-of-simple-types-through-reflection – Maarten Mar 25 '14 at 08:54

1 Answers1

0

string, int? and List<MyClass.ViewModel> are all C# constructs. They're not in .NET itself.

So you simply have to build a lookup table or a giant switch to convert the type names to .NET keywords.

Luaan
  • 62,244
  • 7
  • 97
  • 116