Skip to content

Commit 2f09e5b

Browse files
committed
Add AttributeUtils.GetNativeNameOrDefault()
1 parent ed90465 commit 2f09e5b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

sources/SilkTouch/SilkTouch/Mods/Common/AttributeUtils.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,38 @@ private static SyntaxList<AttributeListSyntax> AddNamePrefixOrSuffix(this IEnume
227227
];
228228
}
229229

230+
/// <summary>
231+
/// Gets the native name or returns the specified default.
232+
/// </summary>
233+
/// <remarks>
234+
/// The default usually should be the node's identifier.
235+
/// </remarks>
236+
public static string GetNativeNameOrDefault(this IEnumerable<AttributeListSyntax> attributeLists, SyntaxToken identifier)
237+
{
238+
if (TryGetNativeName(attributeLists, out var nativeName))
239+
{
240+
return nativeName;
241+
}
242+
243+
return identifier.ToString();
244+
}
245+
246+
/// <summary>
247+
/// Gets the native name or returns the specified default.
248+
/// </summary>
249+
/// <remarks>
250+
/// The default usually should be the node's identifier.
251+
/// </remarks>
252+
public static string GetNativeNameOrDefault(this IEnumerable<AttributeListSyntax> attributeLists, string defaultName)
253+
{
254+
if (TryGetNativeName(attributeLists, out var nativeName))
255+
{
256+
return nativeName;
257+
}
258+
259+
return defaultName;
260+
}
261+
230262
/// <summary>
231263
/// Gets the value of the native name attribute from the given attribute list.
232264
/// </summary>

sources/SilkTouch/SilkTouch/Mods/MixKhronosData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ private class RewriterPhase3(HashSet<string> vendors, HashSet<string> excludedId
20412041
{
20422042
private SyntaxList<AttributeListSyntax> ProcessAndGetNewAttributes(SyntaxList<AttributeListSyntax> attributeLists, SyntaxToken identifier)
20432043
{
2044-
var name = attributeLists.TryGetNativeName(out var nativeName) ? nativeName : identifier.Text;
2044+
var name = attributeLists.GetNativeNameOrDefault(identifier);
20452045

20462046
var handleSuffix = "_T";
20472047
if (name.EndsWith(handleSuffix))

0 commit comments

Comments
 (0)