Skip to content

Commit 0507ea8

Browse files
Added Source Generator
1 parent e4e05e6 commit 0507ea8

File tree

11 files changed

+39
-6
lines changed

11 files changed

+39
-6
lines changed

src/ThunderDesign.Net-PCL.SourceGenerators/ThunderDesign.Net-PCL.SourceGenerators.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<ProjectReference Include="..\ThunderDesign.Net-PCL.Threading\ThunderDesign.Net-PCL.Threading.csproj" />
27+
<ProjectReference Include="..\ThunderDesign.Net-PCL.Threading.Shared\ThunderDesign.Net-PCL.Threading.Shared.csproj" />
2828
</ItemGroup>
2929

30-
<!--<ItemGroup>
31-
<Analyzer Include="$(TargetPath)" Pack="true" />
32-
</ItemGroup>-->
33-
30+
<ItemGroup>
31+
<None Include="$(OutputPath)$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" />
32+
</ItemGroup>
33+
3434
</Project>

src/ThunderDesign.Net-PCL.SourceGenerators/UnifiedPropertyGenerator.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.CodeAnalysis.CSharp.Syntax;
44
using Microsoft.CodeAnalysis.Text;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Text;
89

@@ -13,6 +14,10 @@ public class UnifiedPropertyGenerator : IIncrementalGenerator
1314
{
1415
public void Initialize(IncrementalGeneratorInitializationContext context)
1516
{
17+
//if (!Debugger.IsAttached)
18+
//{
19+
// Debugger.Launch();
20+
//}
1621
// Collect all fields with [BindableProperty] or [Property]
1722
var fieldsWithAttribute = context.SyntaxProvider
1823
.CreateSyntaxProvider(
@@ -253,7 +258,13 @@ public virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMem
253258
if (!string.IsNullOrEmpty(ns))
254259
source.AppendLine("}");
255260

256-
context.AddSource($"{classSymbol.Name}_AllProperties.g.cs", SourceText.From(source.ToString(), Encoding.UTF8));
261+
// Ensure unique hintName by including the full metadata name
262+
var safeClassName = classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
263+
.Replace(".", "_")
264+
.Replace("global::", "");
265+
var hintName = $"{safeClassName}_AllProperties.g.cs";
266+
267+
context.AddSource(hintName, SourceText.From(source.ToString(), Encoding.UTF8));
257268
}
258269

259270
private static bool ImplementsInterface(INamedTypeSymbol type, string interfaceName)

src/ThunderDesign.Net-PCL.Threading/Extentions/IBindableObjectExtention.cs renamed to src/ThunderDesign.Net-PCL.Threading.Shared/Extentions/IBindableObjectExtention.cs

File renamed without changes.

src/ThunderDesign.Net-PCL.Threading/Extentions/INotifyPropertyChangedExtension.cs renamed to src/ThunderDesign.Net-PCL.Threading.Shared/Extentions/INotifyPropertyChangedExtension.cs

File renamed without changes.

src/ThunderDesign.Net-PCL.Threading/Extentions/ObjectExtention.cs renamed to src/ThunderDesign.Net-PCL.Threading.Shared/Extentions/ObjectExtention.cs

File renamed without changes.

src/ThunderDesign.Net-PCL.Threading/HelperClasses/ThreadHelper.cs renamed to src/ThunderDesign.Net-PCL.Threading.Shared/HelperClasses/ThreadHelper.cs

File renamed without changes.

src/ThunderDesign.Net-PCL.Threading/Interfaces/IBindableObject.cs renamed to src/ThunderDesign.Net-PCL.Threading.Shared/Interfaces/IBindableObject.cs

File renamed without changes.

src/ThunderDesign.Net-PCL.Threading/Objects/ThreadObject.cs renamed to src/ThunderDesign.Net-PCL.Threading.Shared/Objects/ThreadObject.cs

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net461;net6.0;net8.0</TargetFrameworks>
5+
<RootNamespace>ThunderDesign.Net_PCL.Threading.Shared</RootNamespace>
6+
</PropertyGroup>
7+
8+
</Project>

src/ThunderDesign.Net-PCL.Threading.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThunderDesign.Net-PCL.Threa
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThunderDesign.Net-PCL.SourceGenerators", "ThunderDesign.Net-PCL.SourceGenerators\ThunderDesign.Net-PCL.SourceGenerators.csproj", "{B6E37583-F5E2-4550-A387-58C36F8298A4}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThunderDesign.Net-PCL.Threading.Shared", "ThunderDesign.Net-PCL.Threading.Shared\ThunderDesign.Net-PCL.Threading.Shared.csproj", "{66B44DB3-424C-45F2-876F-BC43D1D07A85}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{B6E37583-F5E2-4550-A387-58C36F8298A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{B6E37583-F5E2-4550-A387-58C36F8298A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{B6E37583-F5E2-4550-A387-58C36F8298A4}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{66B44DB3-424C-45F2-876F-BC43D1D07A85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{66B44DB3-424C-45F2-876F-BC43D1D07A85}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{66B44DB3-424C-45F2-876F-BC43D1D07A85}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{66B44DB3-424C-45F2-876F-BC43D1D07A85}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)