Skip to content

Commit

Permalink
Add FlagsExAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
kochounoyume committed Nov 21, 2024
1 parent 5da99e1 commit 23752b4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
61 changes: 61 additions & 0 deletions Packages/MinimalUtility/Runtime/FlagsExAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace MinimalUtility
{
/// <summary>
/// <see cref="System.FlagsAttribute"/>の拡張版.
/// </summary>
/// <remarks>
/// 以下のようなコードを自動生成して、foreach文で保持フラグの列挙を可能にする.その必要がなければ、<see cref="System.FlagsAttribute"/>を使用推奨.
/// </remarks>
/// <example>
/// <code>
/// <![CDATA[
/// using System.Runtime.CompilerServices;
///
/// namespace MinimalUtility
/// {
/// internal static class HogeExtensions
/// {
///
/// [MethodImpl(MethodImplOptions.AggressiveInlining)]
/// public static Enumerator GetEnumerator(this Hoge value)
/// {
/// return new Enumerator(value);
/// }
///
/// public struct Enumerator
/// {
/// private Hoge value;
///
/// public Hoge Current { get; private set; }
///
/// internal Enumerator(Hoge value)
/// {
/// this.value = value;
/// Current = default;
/// }
///
/// /// <inheritdoc/>
/// public bool MoveNext()
/// {
/// var flags = (int)value;
/// if (flags == 0) return false;
/// Current = (Hoge)(flags & -flags); // get lowest flag
/// value &= ~Current;
/// return true;
/// }
/// }
/// }
/// }
/// ]]>
/// </code>
/// </example>
public sealed class FlagsExAttribute : System.FlagsAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="FlagsExAttribute"/> class.
/// </summary>
public FlagsExAttribute() : base()
{
}
}
}
3 changes: 3 additions & 0 deletions Packages/MinimalUtility/Runtime/FlagsExAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion Packages/MinimalUtility/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jp.kochounoyume.minimal.utility",
"displayName": "MinimalUtility",
"version": "1.2.3",
"version": "1.2.4",
"unity": "2022.3",
"keyword": [
"Debug",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void IIncrementalGenerator.Initialize(IncrementalGeneratorInitializationContext
.Collect();
context.RegisterSourceOutput(methods, RegisterCoreImplementation);
var flagsAttributeSources = context.SyntaxProvider.ForAttributeWithMetadataName(
typeof(FlagsAttribute).FullName!,
"MinimalUtility.FlagsExAttribute",
static (_, token) =>
{
token.ThrowIfCancellationRequested();
Expand Down

0 comments on commit 23752b4

Please sign in to comment.