@@ -15,10 +15,6 @@ namespace ILSpyX.Backend.Decompiler;
1515
1616public class CSharpLanguage : ILanguage
1717{
18- public CSharpLanguage ( )
19- {
20- }
21-
2218 public string EventToString ( IEvent @event , bool includeDeclaringTypeName , bool includeNamespace , bool includeNamespaceOfDeclaringTypeName )
2319 {
2420 if ( @event == null )
@@ -49,8 +45,10 @@ public string GetEntityName(MetadataFile module, EntityHandle handle, bool fullN
4945 var declaringType = fd . GetDeclaringType ( ) ;
5046 if ( fullName )
5147 {
52- return ToCSharpString ( metadata , declaringType , fullName , omitGenerics ) + "." + metadata . GetString ( fd . Name ) ;
48+ return ToCSharpString ( metadata , declaringType , fullName , omitGenerics ) + "." +
49+ metadata . GetString ( fd . Name ) ;
5350 }
51+
5452 return metadata . GetString ( fd . Name ) ;
5553 case HandleKind . MethodDefinition :
5654 var md = metadata . GetMethodDefinition ( ( MethodDefinitionHandle ) handle ) ;
@@ -61,21 +59,29 @@ public string GetEntityName(MetadataFile module, EntityHandle handle, bool fullN
6159 case ".ctor" :
6260 case ".cctor" :
6361 var td = metadata . GetTypeDefinition ( declaringType ) ;
64- methodName = ReflectionHelper . SplitTypeParameterCountFromReflectionName ( metadata . GetString ( td . Name ) ) ;
62+ methodName =
63+ ReflectionHelper . SplitTypeParameterCountFromReflectionName ( metadata . GetString ( td . Name ) ) ;
6564 break ;
6665 case "Finalize" :
67- const MethodAttributes finalizerAttributes = ( MethodAttributes . Virtual | MethodAttributes . Family | MethodAttributes . HideBySig ) ;
66+ const MethodAttributes finalizerAttributes = ( MethodAttributes . Virtual |
67+ MethodAttributes . Family |
68+ MethodAttributes . HideBySig ) ;
6869 if ( ( md . Attributes & finalizerAttributes ) != finalizerAttributes )
6970 {
7071 goto default ;
7172 }
72- var methodSignature = md . DecodeSignature ( MetadataExtensions . MinimalSignatureTypeProvider , default ) ;
73+
74+ MethodSignature < IType > methodSignature =
75+ md . DecodeSignature ( MetadataExtensions . MinimalSignatureTypeProvider , default ) ;
7376 if ( methodSignature . GenericParameterCount != 0 || methodSignature . ParameterTypes . Length != 0 )
7477 {
7578 goto default ;
7679 }
80+
7781 td = metadata . GetTypeDefinition ( declaringType ) ;
78- methodName = "~" + ReflectionHelper . SplitTypeParameterCountFromReflectionName ( metadata . GetString ( td . Name ) ) ;
82+ methodName = "~" +
83+ ReflectionHelper . SplitTypeParameterCountFromReflectionName (
84+ metadata . GetString ( td . Name ) ) ;
7985 break ;
8086 default :
8187 var genericParams = md . GetGenericParameters ( ) ;
@@ -106,19 +112,23 @@ public string GetEntityName(MetadataFile module, EntityHandle handle, bool fullN
106112 declaringType = metadata . GetMethodDefinition ( ed . GetAccessors ( ) . GetAny ( ) ) . GetDeclaringType ( ) ;
107113 if ( fullName && ! declaringType . IsNil )
108114 {
109- return ToCSharpString ( metadata , declaringType , fullName , omitGenerics ) + "." + metadata . GetString ( ed . Name ) ;
115+ return ToCSharpString ( metadata , declaringType , fullName , omitGenerics ) + "." +
116+ metadata . GetString ( ed . Name ) ;
110117 }
118+
111119 return metadata . GetString ( ed . Name ) ;
112120 case HandleKind . PropertyDefinition :
113121 var pd = metadata . GetPropertyDefinition ( ( PropertyDefinitionHandle ) handle ) ;
114122 declaringType = metadata . GetMethodDefinition ( pd . GetAccessors ( ) . GetAny ( ) ) . GetDeclaringType ( ) ;
115123 if ( fullName && ! declaringType . IsNil )
116124 {
117- return ToCSharpString ( metadata , declaringType , fullName , omitGenerics ) + "." + metadata . GetString ( pd . Name ) ;
125+ return ToCSharpString ( metadata , declaringType , fullName , omitGenerics ) + "." +
126+ metadata . GetString ( pd . Name ) ;
118127 }
128+
119129 return metadata . GetString ( pd . Name ) ;
120130 default :
121- return "" ;
131+ return null ;
122132 }
123133 }
124134
@@ -127,6 +137,36 @@ public string GetTooltip(IEntity entity)
127137 return "" ;
128138 }
129139
140+ public string TypeToString ( IType type ,
141+ ConversionFlags conversionFlags = ConversionFlags . None | ConversionFlags . UseFullyQualifiedTypeNames |
142+ ConversionFlags . UseFullyQualifiedEntityNames )
143+ {
144+ if ( type == null )
145+ throw new ArgumentNullException ( nameof ( type ) ) ;
146+ var ambience = CreateAmbience ( ) ;
147+ // Do not forget to update CSharpAmbienceTests.ILSpyMainTreeViewFlags, if this ever changes.
148+ ambience . ConversionFlags |= conversionFlags ;
149+ if ( type is ITypeDefinition definition )
150+ {
151+ return ambience . ConvertSymbol ( definition ) ;
152+ }
153+ else
154+ {
155+ return ambience . ConvertType ( type ) ;
156+ }
157+ }
158+
159+ public string EntityToString ( IEntity entity , ConversionFlags conversionFlags )
160+ {
161+ // Do not forget to update CSharpAmbienceTests, if this ever changes.
162+ var ambience = CreateAmbience ( ) ;
163+ ambience . ConversionFlags |= conversionFlags
164+ | ConversionFlags . ShowReturnType
165+ | ConversionFlags . ShowParameterList
166+ | ConversionFlags . ShowParameterModifiers ;
167+ return ambience . ConvertSymbol ( entity ) ;
168+ }
169+
130170 public string MethodToString ( IMethod method , bool includeDeclaringTypeName , bool includeNamespace , bool includeNamespaceOfDeclaringTypeName )
131171 {
132172 if ( method == null )
0 commit comments