Retrieve generic contract names for Managed Extensibility Framework
The code in the question was an attempt to generate type contract names, from the way I saw how MEF created them. Especially the difference from Type.FullName, which was previously used, when getting a contract name. For this reason, the code is a probably inferior re-implementation of MEF's own name generation, and should not be used for this purpose.

This is the contract name resolution used by MEF in .NET framework (maybe different namespace in Core, Apps etc.):

Namespace:


System.ComponentModel.Composition



Static method:


AttributedModelServices.GetContractName(Type)



Unfortunately, it's often easier to re-invent the wheel, than to find out about existing implementations...