Skip to content

Commit

Permalink
Interactive test
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaeler committed May 26, 2023
1 parent 2ea9aa4 commit 93134fc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ConsoleTest/ConsoleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<!--<ImplicitUsings>enable</ImplicitUsings>-->
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
15 changes: 15 additions & 0 deletions src/ConsoleTest/FileScopedClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SpeedyGenerators;

namespace ConsoleTest;

internal partial class FileScopedClass
{
[MakeProperty("MyProperty")]
private int _myField;
}
29 changes: 29 additions & 0 deletions src/LibraryTest/FileScopedClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SpeedyGenerators;

namespace LibraryTest;

internal partial class ClassOutsideNamespace
{
[MakeProperty("MyProperty")]
private int _myField1;
}

file partial class FileScopedClass
{
// Cannot use source generators with file scoped classes because
// - source generators must create a separate source file
// - file scoped classes must reside in the same file
//[MakeProperty("YourProperty")]
//protected int _yourField1;
}

// file scoped partial classes can be defined only in the same file
file partial class FileSCopedClass
{
}
4 changes: 2 additions & 2 deletions src/LibraryTest/ShortDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LibraryTest
{
internal partial class ShortDemo
{
[MakeProperty("Name")]
private string? _name;
//[MakeProperty("Name")]
//private string? _name;
}
}
6 changes: 6 additions & 0 deletions src/SpeedyGenerators/PropertyChangedGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
.FirstOrDefault()
?.Name
?.ToString();

namespaceName ??= editedClass.Ancestors()
.OfType<FileScopedNamespaceDeclarationSyntax>()
.FirstOrDefault()
?.Name
?.ToString();

namespaceName ??= String.Empty;
var className = editedClass.Identifier.ToString();
var fullName = $"{namespaceName}.{className}";
Expand Down

0 comments on commit 93134fc

Please sign in to comment.