Skip to content

Commit ef77d09

Browse files
authored
Merge pull request #77 from CommunityToolkit/dev/strip-generator-attributes
Strip source generator attributes by default
2 parents f7a980e + e31a088 commit ef77d09

File tree

12 files changed

+152
-1
lines changed

12 files changed

+152
-1
lines changed

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoNotifyCanExecuteForAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics;
67
using System.Linq;
78
using CommunityToolkit.Mvvm.Input;
89

@@ -49,6 +50,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
4950
/// </code>
5051
/// </summary>
5152
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
53+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
5254
public sealed class AlsoNotifyCanExecuteForAttribute : Attribute
5355
{
5456
/// <summary>

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoNotifyChangeForAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.ComponentModel;
7+
using System.Diagnostics;
78
using System.Linq;
89

910
namespace CommunityToolkit.Mvvm.ComponentModel;
@@ -68,6 +69,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
6869
/// </code>
6970
/// </summary>
7071
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
72+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
7173
public sealed class AlsoNotifyChangeForAttribute : Attribute
7274
{
7375
/// <summary>

CommunityToolkit.Mvvm/ComponentModel/Attributes/INotifyPropertyChangedAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.ComponentModel;
7+
using System.Diagnostics;
78

89
namespace CommunityToolkit.Mvvm.ComponentModel;
910

@@ -24,6 +25,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
2425
/// </para>
2526
/// </summary>
2627
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
28+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
2729
public sealed class INotifyPropertyChangedAttribute : Attribute
2830
{
2931
/// <summary>

CommunityToolkit.Mvvm/ComponentModel/Attributes/ObservableObjectAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.ComponentModel;
7+
using System.Diagnostics;
78

89
namespace CommunityToolkit.Mvvm.ComponentModel;
910

@@ -26,6 +27,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
2627
/// And with this, the same APIs from <see cref="ObservableObject"/> will be available on this type as well.
2728
/// </summary>
2829
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
30+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
2931
public sealed class ObservableObjectAttribute : Attribute
3032
{
3133
}

CommunityToolkit.Mvvm/ComponentModel/Attributes/ObservablePropertyAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.ComponentModel;
7+
using System.Diagnostics;
78

89
namespace CommunityToolkit.Mvvm.ComponentModel;
910

@@ -51,6 +52,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
5152
/// source field name will be converted to uppercase (eg. <c>isEnabled</c> to <c>IsEnabled</c>).
5253
/// </remarks>
5354
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
55+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
5456
public sealed class ObservablePropertyAttribute : Attribute
5557
{
5658
}

CommunityToolkit.Mvvm/ComponentModel/Attributes/ObservableRecipientAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics;
67

78
namespace CommunityToolkit.Mvvm.ComponentModel;
89

@@ -40,6 +41,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
4041
/// If this condition is not met, the code will fail to build.
4142
/// </remarks>
4243
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
44+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
4345
public sealed class ObservableRecipientAttribute : Attribute
4446
{
4547
}

CommunityToolkit.Mvvm/Input/Attributes/ICommandAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics;
67
using System.Windows.Input;
78

89
namespace CommunityToolkit.Mvvm.Input;
@@ -60,6 +61,7 @@ namespace CommunityToolkit.Mvvm.Input;
6061
/// </para>
6162
/// </summary>
6263
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
64+
[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")]
6365
public sealed class ICommandAttribute : Attribute
6466
{
6567
/// <summary>

dotnet Community Toolkit.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Mvvm.Disab
7474
EndProject
7575
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Mvvm.Internals.UnitTests", "tests\CommunityToolkit.Mvvm.Internals.UnitTests\CommunityToolkit.Mvvm.Internals.UnitTests.csproj", "{743D74BA-12AE-4639-AD77-B9DDA9C03255}"
7676
EndProject
77+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Mvvm.KeepSourceGeneratorAttributes.UnitTests", "tests\CommunityToolkit.Mvvm.KeepSourceGeneratorAttributes.UnitTests\CommunityToolkit.Mvvm.KeepSourceGeneratorAttributes.UnitTests.csproj", "{AFB55517-3B50-47E3-B9CA-F1C2770479B6}"
78+
EndProject
7779
Global
7880
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7981
Debug|Any CPU = Debug|Any CPU
@@ -348,6 +350,26 @@ Global
348350
{743D74BA-12AE-4639-AD77-B9DDA9C03255}.Release|x64.Build.0 = Release|Any CPU
349351
{743D74BA-12AE-4639-AD77-B9DDA9C03255}.Release|x86.ActiveCfg = Release|Any CPU
350352
{743D74BA-12AE-4639-AD77-B9DDA9C03255}.Release|x86.Build.0 = Release|Any CPU
353+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
354+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
355+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|ARM.ActiveCfg = Debug|Any CPU
356+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|ARM.Build.0 = Debug|Any CPU
357+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|ARM64.ActiveCfg = Debug|Any CPU
358+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|ARM64.Build.0 = Debug|Any CPU
359+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|x64.ActiveCfg = Debug|Any CPU
360+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|x64.Build.0 = Debug|Any CPU
361+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|x86.ActiveCfg = Debug|Any CPU
362+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Debug|x86.Build.0 = Debug|Any CPU
363+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
364+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|Any CPU.Build.0 = Release|Any CPU
365+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|ARM.ActiveCfg = Release|Any CPU
366+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|ARM.Build.0 = Release|Any CPU
367+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|ARM64.ActiveCfg = Release|Any CPU
368+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|ARM64.Build.0 = Release|Any CPU
369+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|x64.ActiveCfg = Release|Any CPU
370+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|x64.Build.0 = Release|Any CPU
371+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|x86.ActiveCfg = Release|Any CPU
372+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6}.Release|x86.Build.0 = Release|Any CPU
351373
EndGlobalSection
352374
GlobalSection(SolutionProperties) = preSolution
353375
HideSolutionNode = FALSE
@@ -365,6 +387,7 @@ Global
365387
{6640D447-C28D-4DBB-91F4-3ADCE0CA64AD} = {B30036C4-D514-4E5B-A323-587A061772CE}
366388
{9E09DA49-4389-4ECE-8B68-EBDB1221DA90} = {6640D447-C28D-4DBB-91F4-3ADCE0CA64AD}
367389
{743D74BA-12AE-4639-AD77-B9DDA9C03255} = {B30036C4-D514-4E5B-A323-587A061772CE}
390+
{AFB55517-3B50-47E3-B9CA-F1C2770479B6} = {6640D447-C28D-4DBB-91F4-3ADCE0CA64AD}
368391
EndGlobalSection
369392
GlobalSection(ExtensibilityGlobals) = postSolution
370393
SolutionGuid = {5403B0C4-F244-4F73-A35C-FE664D0F4345}

tests/CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests/Test_DisableINotifyPropertyChanging.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using CommunityToolkit.Mvvm.ComponentModel;
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
99

10-
namespace CommunityToolkit.Mvvm.UnitTests.Configuration;
10+
namespace CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests;
1111

1212
[TestClass]
1313
public class Test_DisableINotifyPropertyChanging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
5+
<DefineConstants>$(DefineConstants);MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES</DefineConstants>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
10+
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\CommunityToolkit.Mvvm\CommunityToolkit.Mvvm.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)