Skip to content

Commit 779cbfe

Browse files
committed
Remove unnecessary linker unfriendly path in TypeExtensions
1 parent 4427b44 commit 779cbfe

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,7 @@ static string FormatDisplayString(Type type, int genericTypeOffset, ReadOnlySpan
128128
// If the type is nested, recursively format the hierarchy as well
129129
if (type.IsNested)
130130
{
131-
Type? openDeclaringType = type.DeclaringType!;
132-
Type[]? rootGenericArguments = typeArguments.Slice(0, typeArguments.Length - genericTypeOffset).ToArray();
133-
134-
// If the declaring type is generic, we need to reconstruct the closed type
135-
// manually, as the declaring type instance doesn't retain type information.
136-
if (rootGenericArguments.Length > 0)
137-
{
138-
Type? closedDeclaringType = openDeclaringType.GetGenericTypeDefinition().MakeGenericType(rootGenericArguments);
139-
140-
return $"{FormatDisplayString(closedDeclaringType, genericTypeOffset, typeArguments)}.{displayName}";
141-
}
142-
143-
return $"{FormatDisplayString(openDeclaringType, genericTypeOffset, typeArguments)}.{displayName}";
131+
return $"{FormatDisplayString(type.DeclaringType!, genericTypeOffset, typeArguments)}.{displayName}";
144132
}
145133

146134
return $"{type.Namespace}.{displayName}";
@@ -149,21 +137,21 @@ static string FormatDisplayString(Type type, int genericTypeOffset, ReadOnlySpan
149137
// Atomically get or build the display string for the current type.
150138
return DisplayNames.GetValue(type, t =>
151139
{
152-
// By-ref types are displayed as T&
153-
if (t.IsByRef)
140+
// By-ref types are displayed as T&
141+
if (t.IsByRef)
154142
{
155143
t = t.GetElementType()!;
156144

157145
return $"{FormatDisplayString(t, 0, t.GetGenericArguments())}&";
158146
}
159147

160-
// Pointer types are displayed as T*
161-
if (t.IsPointer)
148+
// Pointer types are displayed as T*
149+
if (t.IsPointer)
162150
{
163151
int depth = 0;
164152

165-
// Calculate the pointer indirection level
166-
while (t.IsPointer)
153+
// Calculate the pointer indirection level
154+
while (t.IsPointer)
167155
{
168156
depth++;
169157
t = t.GetElementType()!;
@@ -172,8 +160,8 @@ static string FormatDisplayString(Type type, int genericTypeOffset, ReadOnlySpan
172160
return $"{FormatDisplayString(t, 0, t.GetGenericArguments())}{new string('*', depth)}";
173161
}
174162

175-
// Standard path for concrete types
176-
return FormatDisplayString(t, 0, t.GetGenericArguments());
163+
// Standard path for concrete types
164+
return FormatDisplayString(t, 0, t.GetGenericArguments());
177165
});
178166
}
179167
}

0 commit comments

Comments
 (0)