33// See the LICENSE file in the project root for more information. 
44
55using  System . Diagnostics . Contracts ; 
6+ using  System . Text ; 
67using  Microsoft . CodeAnalysis ; 
78
89namespace  Microsoft . Toolkit . Mvvm . SourceGenerators . Extensions 
@@ -12,6 +13,42 @@ namespace Microsoft.Toolkit.Mvvm.SourceGenerators.Extensions
1213    /// </summary> 
1314    internal  static class  INamedTypeSymbolExtensions 
1415    { 
16+         /// <summary> 
17+         /// Gets the full metadata name for a given <see cref="INamedTypeSymbol"/> instance. 
18+         /// </summary> 
19+         /// <param name="symbol">The input <see cref="INamedTypeSymbol"/> instance.</param> 
20+         /// <returns>The full metadata name for <paramref name="symbol"/>.</returns> 
21+         [ Pure ] 
22+         public  static string  GetFullMetadataName ( this  INamedTypeSymbol  symbol ) 
23+         { 
24+             static StringBuilder  BuildFrom ( ISymbol ?  symbol ,  StringBuilder  builder ) 
25+             { 
26+                 return  symbol  switch 
27+                 { 
28+                     INamespaceSymbol  ns  when  ns . IsGlobalNamespace  =>  builder , 
29+                     INamespaceSymbol  ns  when  ns . ContainingNamespace  is  {  IsGlobalNamespace :  false  } 
30+                         =>  BuildFrom ( ns . ContainingNamespace ,  builder . Insert ( 0 ,  $ ".{ ns . MetadataName } ") ) , 
31+                     ITypeSymbol  ts  when  ts . ContainingType  is  ISymbol  pt  =>  BuildFrom ( pt ,  builder . Insert ( 0 ,  $ "+{ ts . MetadataName } ") ) , 
32+                     ITypeSymbol  ts  when  ts . ContainingNamespace  is  ISymbol  pn  =>  BuildFrom ( pn ,  builder . Insert ( 0 ,  $ ".{ ts . MetadataName } ") ) , 
33+                     ISymbol  =>  BuildFrom ( symbol . ContainingSymbol ,  builder . Insert ( 0 ,  symbol . MetadataName ) ) , 
34+                     _ =>  builder 
35+                 } ; 
36+             } 
37+ 
38+             return  BuildFrom ( symbol ,  new  StringBuilder ( 256 ) ) . ToString ( ) ; 
39+         } 
40+ 
41+         /// <summary> 
42+         /// Gets a valid filename for a given <see cref="INamedTypeSymbol"/> instance. 
43+         /// </summary> 
44+         /// <param name="symbol">The input <see cref="INamedTypeSymbol"/> instance.</param> 
45+         /// <returns>The full metadata name for <paramref name="symbol"/> that is also a valid filename.</returns> 
46+         [ Pure ] 
47+         public  static string  GetFullMetadataNameForFileName ( this  INamedTypeSymbol  symbol ) 
48+         { 
49+             return  symbol . GetFullMetadataName ( ) . Replace ( '`' ,  '-' ) . Replace ( '+' ,  '.' ) ; 
50+         } 
51+ 
1552        /// <summary> 
1653        /// Checks whether or not a given <see cref="INamedTypeSymbol"/> inherits from a specified type. 
1754        /// </summary> 
0 commit comments