Search code examples
c#typestostring

FullName of generic type without assembly info?


I have a database table where I store the height, width, state, et cetera, of windows. As identifier for the windows I use the full type name of form. It works well, but I discovered that some forms that are generic gets names which are incredibly long. The reason is that the generic type is listed with full assembly information. Is there a way to skip that?

For example the full name of a regular form would look like this:

Some.Name.Space.NameOfForm

But the full name of a generic form looks like this:

Some.Name.Space.NameOfForm`1[[Some.Other.Name.Space.GenericType, AssemblyName, Version=1.0.2.0, Cuntulre=neutral, PublicKeyToken=null]]

Why does it get so long? Is there a way I can get a shorter version? For example something like:

Some.Name.Space.NameOfForm`1[[Some.Other.Name.Space.GenericType]]

Any clues?


Solution

  • I agree with dbemerlin in that your end goal seems odd, but I just wanted to point out that

    GetType().ToString();
    

    seems to return a shorter version of the typename (w/o the assembly information of the generic arguments).

    I guess this could be handy for a more human readable version of the type name.