Click here to Skip to main content
11,408,708 members (65,958 online)
Click here to Skip to main content

AssemblyQualifiedName Parser

, 22 Jul 2013 Ms-PL
Rate this:
Please Sign up or sign in to vote.
A parser for AssemblyQualifiedName for .NET

What Is It ?

ParsedAssemblyQualifiedName is a simple parser for type.AssemblyQualifiedName for .NET.

It is a fact that the syntax of AssemblyQualifiedName is rather complex. While I am working on a new version of UniversalSerializer, I need such a parser and I am unable to find one in the Internet. So here is a class that may help.

Summary

As I said, the syntax of AssemblyQualifiedName is rather complex, especially with generics.

An example:

Dictionary<int, List<double>>

has this AssemblyQualifiedName:

System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, 
  Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.Double, 
  mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, 
  Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, 
  Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Not very comprehensible!

ParsedAssemblyQualifiedName will extract these information:

mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

System.Collections.Generic.Dictionary<System.Int32, System.Collections.Generic.List<System.Double>>

neutral

b77a5c561934e089

mscorlib

System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, 
  Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],
  [System.Collections.Generic.List`1[[System.Double, mscorlib, Version=4.0.0.0, 
  Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, 
  Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

System.Collections.Generic.Dictionary(Of System.Int32, System.Collections.Generic.List(Of System.Double))

4.0.0.0
  • AssemblyDescriptionString: This is the assembly description part of the AssemblyQualifiedName.
  • AssemblyNameDescriptor: An AssemblyName generated from the AssemblyQualifiedName. It is Lazy.
  • CSharpStyleName: A C#-style type name. It is Lazy.
  • Culture: Culture string of the Assembly.
  • FoundType: Creates the Type corresponding to the AssemblyQualifiedName, if available. It is Lazy.
  • GenericParameters: Gets a list of ParsedAssemblyQualifiedName, one for each generic parameter. Obviously, it is recursive.
  • PublicKeyToken: The token of the Assembly.
  • ShortAssemblyName
  • TypeName: The first part of the AssemblyQualifiedName, without the Assembly information.
  • VBNetStyleName: A VB-style type name. It is Lazy.
  • Version: Version of the Assembly, as a string.

Note

Please note ParsedAssemblyQualifiedName can analyse a type description even if the type does not exist or if it lays in an inaccessible library. In that case, only FoundType will not produce anything (it will return null).

Example of Usage

var parsed = new ParsedAssemblyQualifiedName
    (typeof(Dictionary<int, List<double>>).AssemblyQualifiedName);
var t = parsed.FoundType.Value;
var an = parsed.AssemblyNameDescriptor.Value;
var cs = parsed.CSharpStyleName.Value;
var vb = parsed.VBNetStyleName.Value;

Conclusion

I hope this small class will be useful to many. Future enhancements will be part of UniversalSerializer.

History

  • 2015-01-28 Correction for array types

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Hi !

I made my first program on a Sinclair ZX-81.
Since that day, I have the virus of computers. Smile | :)

Some articles in my blog:
https://chrisbertrandprogramer.wordpress.com/

Comments and Discussions

 
SuggestionA little improvement... PinmemberFilippo Bottega17-Feb-15 4:58 
GeneralRe: A little improvement... PinmemberChristophe Bertrand20-Feb-15 7:55 
GeneralMy vote of 3 PinmemberMember 1092263116-Jan-15 10:11 
AnswerRe: My vote of 3 PinmemberChristophe Bertrand30-Jan-15 0:39 
GeneralMy vote of 5 PinmemberMember 767332830-Sep-13 18:10 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.5 | Last Updated 22 Jul 2013
Article Copyright 2013 by Christophe Bertrand
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid