Skip to content

Commit 8780c51

Browse files
authored
Merge pull request #159 from postsharp/topic/2024.2/35356-observable
Topic/2024.2/35356 observable
2 parents 1ae06be + ceee774 commit 8780c51

File tree

16 files changed

+186
-175
lines changed

16 files changed

+186
-175
lines changed

.idea/.idea.Metalama.Patterns/.idea/projectSettingsUpdater.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.teamcity/settings.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object DebugBuild : BuildType({
2727

2828
name = "Build [Debug]"
2929

30-
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n"
30+
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n+:artifacts/logs/**/*=>logs\n"
3131

3232
params {
3333
text("BuildArguments", "", label = "Build Arguments", description = "Arguments to append to the 'Build' build step.", allowEmpty = true)
@@ -157,7 +157,7 @@ object ReleaseBuild : BuildType({
157157

158158
name = "Build [Release]"
159159

160-
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n"
160+
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n+:artifacts/logs/**/*=>logs\n"
161161

162162
params {
163163
text("BuildArguments", "", label = "Build Arguments", description = "Arguments to append to the 'Build' build step.", allowEmpty = true)
@@ -278,7 +278,7 @@ object PublicBuild : BuildType({
278278

279279
name = "Build [Public]"
280280

281-
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n"
281+
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n+:artifacts/logs/**/*=>logs\n"
282282

283283
params {
284284
text("BuildArguments", "", label = "Build Arguments", description = "Arguments to append to the 'Build' build step.", allowEmpty = true)
@@ -511,7 +511,7 @@ object PublicDeployment : BuildType({
511511

512512
artifacts {
513513
cleanDestination = true
514-
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults"
514+
artifactRules = "+:artifacts/publish/public/**/*=>artifacts/publish/public\n+:artifacts/publish/private/**/*=>artifacts/publish/private\n+:artifacts/testResults/**/*=>artifacts/testResults\n+:artifacts/logs/**/*=>logs"
515515
}
516516
}
517517

Directory.Packages.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
</PropertyGroup>
66
<!-- Set versions of dependencies that need special treatment or consist of multiple packages of the same version. -->
77
<PropertyGroup>
8-
<PostSharpEngineeringVersion Condition="'$(PostSharpEngineeringVersion)'==''">2023.2.111</PostSharpEngineeringVersion>
8+
<PostSharpEngineeringVersion Condition="'$(PostSharpEngineeringVersion)'==''">2023.2.117</PostSharpEngineeringVersion>
9+
<StyleCopVersion>1.2.0-beta.556</StyleCopVersion>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<PackageVersion Include="Azure.Identity" Version="1.11.4" />
@@ -32,6 +33,6 @@
3233
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
3334
<PackageVersion Include="System.Threading.Thread" Version="4.3.0" />
3435
<PackageVersion Include="System.Threading.ThreadPool" Version="4.3.0" />
35-
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.1.0"/>
36+
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.1.0" />
3637
</ItemGroup>
3738
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"rollForward": "patch"
55
},
66
"msbuild-sdks": {
7-
"PostSharp.Engineering.Sdk": "2023.2.111"
7+
"PostSharp.Engineering.Sdk": "2023.2.117"
88
}
99
}

src/Metalama.Patterns.Caching.Aspects/InvalidateCacheAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private static bool ValidateAndFindInvalidatedMethods(
391391

392392
// Match parameter by name.
393393
var invalidatingMethodParameter =
394-
invalidatingMethodParameters.FirstOrDefault( p => p.Name == invalidatedMethodParameter.Name );
394+
invalidatingMethodParameters.OfName( invalidatedMethodParameter.Name );
395395

396396
if ( invalidatingMethodParameter == null )
397397
{

src/Metalama.Patterns.Contracts/NotEmptyAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private static bool TryGetCompatibleTargetInterface(
136136

137137
if ( targetType.Is( typeOfICollection ) )
138138
{
139-
var countProperty = typeOfICollection.Properties.Single( p => p.Name == nameof(ICollection.Count) );
139+
var countProperty = typeOfICollection.Properties.OfName( nameof(ICollection.Count) ).Single();
140140
targetType.TryFindImplementationForInterfaceMember( countProperty, out var countPropertyImpl );
141141

142142
interfaceType = typeOfICollection;
@@ -169,7 +169,7 @@ private static bool TryGetCompatibleTargetInterface(
169169

170170
if ( foundInterface != null )
171171
{
172-
var countProperty = foundInterface.Properties.Single( p => p.Name == "Count" );
172+
var countProperty = foundInterface.Properties.OfName( "Count" ).Single();
173173
targetType.TryFindImplementationForInterfaceMember( countProperty, out var countPropertyImpl );
174174

175175
interfaceType = foundInterface;

src/Metalama.Patterns.Observability/Implementation/Assets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ public Assets()
4242
/// Gets the <see cref="IProperty"/> for property <c>EqualityComparer<paramref name="type"/>>.Default</c>.
4343
/// </summary>
4444
public IProperty GetDefaultEqualityComparerForType( IType type )
45-
=> this.EqualityComparerOfT.WithTypeArguments( type ).Properties.Single( p => p.Name == "Default" );
45+
=> this.EqualityComparerOfT.WithTypeArguments( type ).Properties.OfName( "Default" ).Single();
4646
}

src/Metalama.Patterns.Observability/Implementation/ClassicStrategy/ClassicDependencyGraphBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal sealed class ClassicDependencyGraphBuilder : DependencyGraphBuilder
1313

1414
public INamedType CurrentType { get; }
1515

16-
public ClassicDependencyGraphBuilder( ClassicGraphBuildingContext context, INamedType currentType )
16+
public ClassicDependencyGraphBuilder( ClassicGraphBuildingContext context, INamedType currentType ) : base( context.Assets )
1717
{
1818
this.Context = context;
1919
this.CurrentType = currentType;

src/Metalama.Patterns.Observability/Implementation/ClassicStrategy/ClassicGraphBuildingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal sealed class ClassicGraphBuildingContext : GraphBuildingContext
1515
{
1616
private readonly ClassicObservabilityStrategyImpl _strategy;
1717

18-
public ClassicGraphBuildingContext( ClassicObservabilityStrategyImpl strategy ) : base( strategy.CurrentType.Compilation )
18+
public ClassicGraphBuildingContext( ClassicObservabilityStrategyImpl strategy ) : base( strategy.CurrentType.Compilation, strategy.Assets )
1919
{
2020
this._strategy = strategy;
2121
}

src/Metalama.Patterns.Observability/Implementation/ClassicStrategy/ClassicObservabilityStrategyImpl.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ internal sealed class ClassicObservabilityStrategyImpl : IObservabilityStrategy
2727
private readonly IMethod? _baseOnPropertyChangedOverridableMethod;
2828
private readonly IMethod? _baseOnChildPropertyChangedMethod;
2929
private readonly IMethod? _baseOnObservablePropertyChangedMethod;
30-
private readonly Assets _assets;
3130
private readonly bool _targetImplementsInpc;
3231

32+
public Assets Assets { get; }
33+
3334
// Useful to see when debugging:
3435
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
3536
private readonly bool _baseImplementsInpc;
@@ -52,23 +53,23 @@ public ClassicObservabilityStrategyImpl( IAspectBuilder<INamedType> aspectBuilde
5253
var target = aspectBuilder.Target;
5354

5455
this.AspectBuilder = aspectBuilder;
55-
this._assets = target.Compilation.Cache.GetOrAdd( _ => new Assets() );
56-
this.InpcInstrumentationKindLookup = new InpcInstrumentationKindLookup( this.CurrentType, this._assets );
56+
this.Assets = target.Compilation.Cache.GetOrAdd( _ => new Assets() );
57+
this.InpcInstrumentationKindLookup = new InpcInstrumentationKindLookup( this.CurrentType, this.Assets );
5758
this._commonOptions = this.CurrentType.Enhancements().GetOptions<ObservabilityOptions>();
5859
this._classicOptions = this.CurrentType.Enhancements().GetOptions<ClassicObservabilityStrategyOptions>();
5960

6061
// TODO: Consider using BaseType.Definition where possible for better performance.
6162

6263
this._baseImplementsInpc =
6364
target.BaseType != null && (
64-
target.BaseType.Is( this._assets.INotifyPropertyChanged )
65+
target.BaseType.Is( this.Assets.INotifyPropertyChanged )
6566
|| (target.BaseType is { BelongsToCurrentProject: true }
6667
&& target.BaseType.Definition.Enhancements().HasAspect( typeof(ObservableAttribute) )));
6768

68-
this._targetImplementsInpc = this._baseImplementsInpc || target.Is( this._assets.INotifyPropertyChanged );
69+
this._targetImplementsInpc = this._baseImplementsInpc || target.Is( this.Assets.INotifyPropertyChanged );
6970
(this._baseOnPropertyChangedInvocableMethod, this._baseOnPropertyChangedOverridableMethod) = GetOnPropertyChangedMethods( target );
7071
this._baseOnChildPropertyChangedMethod = GetOnChildPropertyChangedMethod( target );
71-
this._baseOnObservablePropertyChangedMethod = GetOnObservablePropertyChangedMethod( target, this._assets );
72+
this._baseOnObservablePropertyChangedMethod = GetOnObservablePropertyChangedMethod( target, this.Assets );
7273

7374
var useOnObservablePropertyChangedMethod =
7475
this._classicOptions.EnableOnObservablePropertyChangedMethod == true &&
@@ -128,7 +129,7 @@ public void BuildAspect( IAspectBuilder<INamedType> builder )
128129
this._commonOptions,
129130
this._classicOptions,
130131
this.CurrentType,
131-
this._assets,
132+
this.Assets,
132133
this.InpcInstrumentationKindLookup,
133134
this.ObservableTypeInfo,
134135
this._onObservablePropertyChangedMethod?.Value,
@@ -154,7 +155,7 @@ private bool ValidateRootAutoProperties()
154155
.Where(
155156
p =>
156157
p is { IsStatic: false, IsAutoPropertyOrField: true }
157-
&& !p.Attributes.Any( this._assets.NotObservableAttribute ) );
158+
&& !p.Attributes.Any( this.Assets.NotObservableAttribute ) );
158159

159160
var allValid = true;
160161

@@ -316,7 +317,7 @@ private bool TryIntroduceOnChildPropertyChangedMethod()
316317
{
317318
b.AddAttribute(
318319
AttributeConstruction.Create(
319-
this._assets.InvokedForAttribute,
320+
this.Assets.InvokedForAttribute,
320321
this._propertyPathsForOnChildPropertyChangedMethod.OrderBy( s => s ).ToArray() ) );
321322
}
322323

@@ -383,7 +384,7 @@ private bool TryIntroduceOnObservablePropertyChanged()
383384
{
384385
b.AddAttribute(
385386
AttributeConstruction.Create(
386-
this._assets.InvokedForAttribute,
387+
this.Assets.InvokedForAttribute,
387388
this._propertyNamesForOnObservablePropertyChangedMethod.OrderBy( s => s ).ToArray() ) );
388389
}
389390

@@ -447,7 +448,7 @@ private void IntroduceInterfaceIfRequired()
447448
if ( !this._targetImplementsInpc )
448449
{
449450
this.AspectBuilder.Advice.WithTemplateProvider( Templates.Provider )
450-
.ImplementInterface( this.CurrentType, this._assets.INotifyPropertyChanged );
451+
.ImplementInterface( this.CurrentType, this.Assets.INotifyPropertyChanged );
451452
}
452453
}
453454

@@ -539,7 +540,7 @@ private void ProcessAutoPropertiesAndReferencedFields()
539540
target.Fields
540541
.Where( f => f is { IsStatic: false, IsImplicitlyDeclared: false } )
541542
.Select( p => (ClassicObservablePropertyInfo) this.ObservableTypeInfo.GetOrAddProperty( p ) ) )
542-
.Where( node => !node.FieldOrProperty.Attributes.Any( this._assets.NotObservableAttribute ) )
543+
.Where( node => !node.FieldOrProperty.Attributes.Any( this.Assets.NotObservableAttribute ) )
543544
.ToList();
544545

545546
foreach ( var propertyInfo in properties )
@@ -645,7 +646,7 @@ private void ProcessAutoPropertiesAndReferencedFields()
645646
public bool HasInheritedOnChildPropertyChangedPropertyPath( string parentPropertyPath )
646647
{
647648
this._inheritedOnChildPropertyChangedPropertyPaths ??=
648-
BuildPropertyPathLookup( GetPropertyPaths( this._assets.InvokedForAttribute, this._baseOnChildPropertyChangedMethod ) );
649+
BuildPropertyPathLookup( GetPropertyPaths( this.Assets.InvokedForAttribute, this._baseOnChildPropertyChangedMethod ) );
649650

650651
return this._inheritedOnChildPropertyChangedPropertyPaths.Contains( parentPropertyPath );
651652
}
@@ -657,7 +658,7 @@ public bool HasInheritedOnObservablePropertyChangedProperty( string propertyName
657658
this._inheritedOnObservablePropertyChangedPropertyNames ??=
658659
BuildPropertyPathLookup(
659660
GetPropertyPaths(
660-
this._assets.InvokedForAttribute,
661+
this.Assets.InvokedForAttribute,
661662
this._baseOnObservablePropertyChangedMethod ) );
662663

663664
return this._inheritedOnObservablePropertyChangedPropertyNames.Contains( propertyName );
@@ -721,7 +722,7 @@ private IField GetOrCreateHandlerField( ClassicObservableExpression node )
721722
.IntroduceField(
722723
this.CurrentType,
723724
handlerFieldName,
724-
this._assets.NullablePropertyChangedEventHandler,
725+
this.Assets.NullablePropertyChangedEventHandler,
725726
IntroductionScope.Instance,
726727
OverrideStrategy.Fail,
727728
b => b.Accessibility = Accessibility.Private );

0 commit comments

Comments
 (0)