Get generic type fullname without assembly version,culture and PublicKeyToken

  • Thread starter Thread starter zlf
  • Start date Start date
Z

zlf

I want to get type name as
System.Collections.Generic.IList`1[[System.String, mscorlib]] for
typeof(IList<string>).
But for now, the closest result I can get is
System.Collections.Generic.IList`1[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] by
calling typeof(IList<string>).FullName. I do not want assembly
version,culture and PublicKeyToken.

Thanks

zlf
 
Well, you could build it up from scratch using reflection,
GetGenericArguments(), FullName, getting the assembly, etc - but I
wonder if a regex isn't easier in this case...

s = Regex.Replace(s, @"(\[[^,]*?,\s*[^,]*?)(,[^\]]*?)(\])", "$1$3");

Marc
 
Back
Top