Support required partial properties
このコミットが含まれているのは:
1 親
9cfa571922
コミット
e80b110023
4ファイル変更
+93
-3
検索条件に一致するファイルはありません
@@ -174,8 +174,10 @@ partial class CanvasEffectPropertyGenerator
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($$"""
|
||||
{{GetExpressionWithTrailingSpace(propertyInfo.DeclaredAccessibility)}}partial {{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}}
|
||||
writer.Write(GetExpressionWithTrailingSpace(propertyInfo.DeclaredAccessibility));
|
||||
writer.WriteIf(propertyInfo.IsRequired, "required ");
|
||||
writer.WriteLine($"partial {propertyInfo.TypeNameWithNullabilityAnnotations} {propertyInfo.PropertyName}");
|
||||
writer.WriteLine($$"""
|
||||
{
|
||||
{{GetExpressionWithTrailingSpace(propertyInfo.GetterAccessibility)}}get => field;
|
||||
{{GetExpressionWithTrailingSpace(propertyInfo.SetterAccessibility)}}set
|
||||
|
||||
@@ -63,7 +63,7 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato
|
||||
}
|
||||
|
||||
// Also ignore all properties that have an invalid declaration
|
||||
if (propertySymbol.IsStatic || propertySymbol.ReturnsByRef || propertySymbol.ReturnsByRefReadonly || propertySymbol.Type.IsRefLikeType)
|
||||
if (propertySymbol.ReturnsByRef || propertySymbol.ReturnsByRefReadonly || propertySymbol.Type.IsRefLikeType)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
@@ -101,6 +101,7 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato
|
||||
// This will cover both reference types as well T when the constraints are not struct or unmanaged.
|
||||
// If this is true, it means the field storage can potentially be in a null state (even if not annotated).
|
||||
bool isReferenceTypeOrUnconstraindTypeParameter = !propertySymbol.Type.IsValueType;
|
||||
bool isRequired = propertySymbol.IsRequired;
|
||||
|
||||
// Finally, get the hierarchy too
|
||||
HierarchyInfo hierarchyInfo = HierarchyInfo.From(typeSymbol);
|
||||
@@ -115,6 +116,7 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato
|
||||
SetterAccessibility: setterAccessibility,
|
||||
TypeNameWithNullabilityAnnotations: typeNameWithNullabilityAnnotations,
|
||||
IsReferenceTypeOrUnconstraindTypeParameter: isReferenceTypeOrUnconstraindTypeParameter,
|
||||
IsRequired: isRequired,
|
||||
InvalidationType: invalidationType);
|
||||
})
|
||||
.WithTrackingName(WellKnownTrackingNames.Execute)
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace ComputeSharp.D2D1.WinUI.SourceGenerators.Models;
|
||||
/// <param name="SetterAccessibility">The accessibility of the <see langword="set"/> accessor, if available.</param>
|
||||
/// <param name="TypeNameWithNullabilityAnnotations">The type name for the generated property, including nullability annotations.</param>
|
||||
/// <param name="IsReferenceTypeOrUnconstraindTypeParameter">Indicates whether the property is of a reference type or an unconstrained type parameter.</param>
|
||||
/// <param name="IsRequired">Whether or not the generated property should be marked as required.</param>
|
||||
/// <param name="InvalidationType">The invalidation type to request.</param>
|
||||
internal sealed record CanvasEffectPropertyInfo(
|
||||
HierarchyInfo Hierarchy,
|
||||
@@ -26,4 +27,5 @@ internal sealed record CanvasEffectPropertyInfo(
|
||||
Accessibility SetterAccessibility,
|
||||
string TypeNameWithNullabilityAnnotations,
|
||||
bool IsReferenceTypeOrUnconstraindTypeParameter,
|
||||
bool IsRequired,
|
||||
CanvasEffectInvalidationType InvalidationType);
|
||||
+84
@@ -344,6 +344,90 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SingleProperty_Required()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public required partial int Number { get; set; }
|
||||
}
|
||||
""";
|
||||
|
||||
const string result = """"
|
||||
// <auto-generated/>
|
||||
#pragma warning disable
|
||||
|
||||
namespace MyNamespace
|
||||
{
|
||||
/// <inheritdoc cref="MyEffect"/>
|
||||
partial class MyEffect
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
public required partial int Number
|
||||
{
|
||||
get => field;
|
||||
set
|
||||
{
|
||||
if (global::System.Collections.Generic.EqualityComparer<int>.Default.Equals(field, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int oldValue = field;
|
||||
|
||||
OnNumberChanging(value);
|
||||
OnNumberChanging(oldValue, value);
|
||||
|
||||
field = value;
|
||||
|
||||
OnNumberChanged(value);
|
||||
OnNumberChanged(oldValue, value);
|
||||
|
||||
InvalidateEffectGraph(global::ComputeSharp.D2D1.WinUI.CanvasEffectInvalidationType.Update);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Executes the logic for when <see cref="Number"/> is changing.</summary>
|
||||
/// <param name="value">The new property value being set.</param>
|
||||
/// <remarks>This method is invoked right before the value of <see cref="Number"/> is changed.</remarks>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", <ASSEMBLY_VERSION>)]
|
||||
partial void OnNumberChanging(int newValue);
|
||||
|
||||
/// <summary>Executes the logic for when <see cref="Number"/> is changing.</summary>
|
||||
/// <param name="oldValue">The previous property value that is being replaced.</param>
|
||||
/// <param name="newValue">The new property value being set.</param>
|
||||
/// <remarks>This method is invoked right before the value of <see cref="Number"/> is changed.</remarks>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", <ASSEMBLY_VERSION>)]
|
||||
partial void OnNumberChanging(int oldValue, int newValue);
|
||||
|
||||
/// <summary>Executes the logic for when <see cref="Number"/> has just changed.</summary>
|
||||
/// <param name="value">The new property value that has been set.</param>
|
||||
/// <remarks>This method is invoked right after the value of <see cref="Number"/> is changed.</remarks>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", <ASSEMBLY_VERSION>)]
|
||||
partial void OnNumberChanged(int newValue);
|
||||
|
||||
/// <summary>Executes the logic for when <see cref="Number"/> has just changed.</summary>
|
||||
/// <param name="oldValue">The previous property value that has been replaced.</param>
|
||||
/// <param name="newValue">The new property value that has been set.</param>
|
||||
/// <remarks>This method is invoked right after the value of <see cref="Number"/> is changed.</remarks>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", <ASSEMBLY_VERSION>)]
|
||||
partial void OnNumberChanged(int oldValue, int newValue);
|
||||
}
|
||||
}
|
||||
"""";
|
||||
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MultipleProperties()
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする