Completed field declaration logic for single type

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-27 13:06:33 +01:00
1 親 d602cb3b5b
コミット 033bed4634
3ファイル変更
+88 -12

検索条件に一致するファイルはありません

+37
ファイルの表示
@@ -0,0 +1,37 @@
using System.Diagnostics.Contracts;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGenerators.Extensions
{
/// <summary>
/// A <see langword="class"/> with some extension methods for the <see cref="AttributeData"/> type.
/// </summary>
internal static class AttributeDataExtension
{
/// <summary>
/// Tries to get a named argument from a given <see cref="AttributeData"/> instance.
/// </summary>
/// <typeparam name="T">The type of value to retrieve.</typeparam>
/// <param name="attributeData">The input <see cref="AttributeData"/> instance to get the value from.</param>
/// <param name="key">The name of the argument to retrieve.</param>
/// <param name="value">The resulting value, if found.</param>
/// <returns>Whether or not the requested argument was found.</returns>
[Pure]
public static bool TryGetNamedArgument<T>(this AttributeData attributeData, string key, out T? value)
{
foreach (var argument in attributeData.NamedArguments)
{
if (argument.Key.Equals(key))
{
value = (T?)argument.Value.Value;
return true;
}
}
value = default;
return false;
}
}
}