Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#
Tip/Trick

How to get FullType From AssemblyQualifiedName (remove Version, Culture and PublicKeyToken)

Rate me:
Please Sign up or sign in to vote.
3.60/5 (4 votes)
7 Oct 2010CPOL 19.3K   2   5
When this code ends, you'll get
"System.String, mscorlib"

instead of

"System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"



string typename = obj.GetType().AssemblyQualifiedName;

typename = Regex.Replace(typename, @", Version=\d+.\d+.\d+.\d+",string.Empty);

typename = Regex.Replace(typename, @", Culture=\w+", string.Empty);

typename = Regex.Replace(typename, @", PublicKeyToken=\w+", string.Empty);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Polenter - Software Solutions
Germany Germany
I'm C# developer from Cologne, Germany. Here I owe a small software company. My hobby is general optimization - natural talent of all lazy people Wink | ;-)

Comments and Discussions

 
QuestionThis is 2024 for the lesser AssemblyQualifiedName Pin
Alphons van der Heijden18-Mar-24 22:11
professionalAlphons van der Heijden18-Mar-24 22:11 
GeneralAs it is about to known as off-topic, I deleted it. :) Pin
Hiren solanki13-Oct-10 20:08
Hiren solanki13-Oct-10 20:08 
GeneralWhat about more generally? i.e. "typing dark letters on a li... Pin
Pawel idzikowski13-Oct-10 7:17
Pawel idzikowski13-Oct-10 7:17 
GeneralReason for my vote of 2 Just change the tip subject as 'Stri... Pin
Hiren solanki13-Oct-10 3:40
Hiren solanki13-Oct-10 3:40 
GeneralReason for my vote of 1 Too complicated Pin
Đỗ Hồng Ngọc7-Oct-10 17:02
professionalĐỗ Hồng Ngọc7-Oct-10 17:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.