diff --git a/readme.md b/readme.md index c4d62ca..e936fc4 100644 --- a/readme.md +++ b/readme.md @@ -41,9 +41,6 @@ The package is a [development dependency](https://github.com/NuGet/Home/wiki/Dev meaning it will not add any run-time dependencies to your project (or package if you publish one that uses struct ids). -The default target namespace for the included types will match the `RootNamespace` of the -project, but can be customized by setting the `StructIdNamespace` property. - You can simply declare a new ID type by implementing `IStructId`: ```csharp diff --git a/src/StructId.Analyzer/CodeTemplate.cs b/src/StructId.Analyzer/CodeTemplate.cs index 1a3ee38..1518193 100644 --- a/src/StructId.Analyzer/CodeTemplate.cs +++ b/src/StructId.Analyzer/CodeTemplate.cs @@ -53,6 +53,9 @@ public static SyntaxNode Apply(this SyntaxNode node, INamedTypeSymbol structId) var tid = iface.TypeArguments.FirstOrDefault()?.ToFullName() ?? "string"; var corens = iface.ContainingNamespace.ToFullName(); + if (string.IsNullOrEmpty(corens)) + corens = nameof(StructId); + var targetNamespace = structId.ContainingNamespace != null && !structId.ContainingNamespace.IsGlobalNamespace ? structId.ContainingNamespace.ToDisplayString() : null; diff --git a/src/StructId.Analyzer/KnownTypes.cs b/src/StructId.Analyzer/KnownTypes.cs index 2b92880..cb2cea3 100644 --- a/src/StructId.Analyzer/KnownTypes.cs +++ b/src/StructId.Analyzer/KnownTypes.cs @@ -20,13 +20,13 @@ public record KnownTypes(Compilation Compilation) /// StructId.IStructId /// public INamedTypeSymbol? IStructId { get; } = Compilation - .GetAllTypes(true) + .GetAllTypes(includeReferenced: true) .FirstOrDefault(x => x.MetadataName == "IStructId" && x.IsGeneratedByStructId()); /// /// StructId.IStructId{T} /// public INamedTypeSymbol? IStructIdT { get; } = Compilation - .GetAllTypes(true) + .GetAllTypes(includeReferenced: true) .FirstOrDefault(x => x.MetadataName == "IStructId`1" && x.IsGeneratedByStructId()); } \ No newline at end of file diff --git a/src/StructId.FunctionalTests/NoNs.cs b/src/StructId.FunctionalTests/NoNs.cs index a0c3559..23c956b 100644 --- a/src/StructId.FunctionalTests/NoNs.cs +++ b/src/StructId.FunctionalTests/NoNs.cs @@ -1,4 +1,5 @@ -using StructId.Functional; +using StructId; +using StructId.Functional; // Showcases that types don't need to have a namespace public partial record struct NoNsId : IStructId; diff --git a/src/StructId.FunctionalTests/StructId.FunctionalTests.csproj b/src/StructId.FunctionalTests/StructId.FunctionalTests.csproj index 3c2a8dd..205fc8c 100644 --- a/src/StructId.FunctionalTests/StructId.FunctionalTests.csproj +++ b/src/StructId.FunctionalTests/StructId.FunctionalTests.csproj @@ -1,5 +1,4 @@  - net8.0 diff --git a/src/StructId.FunctionalTests/UlidEntityFramework.cs b/src/StructId.FunctionalTests/UlidEntityFramework.cs index 7e94b3b..e136bdd 100644 --- a/src/StructId.FunctionalTests/UlidEntityFramework.cs +++ b/src/StructId.FunctionalTests/UlidEntityFramework.cs @@ -2,7 +2,7 @@ #nullable enable using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StructId.Functional; +using StructId; [TStructId] file partial record struct TSelf(Ulid Value) : INewable diff --git a/src/StructId.Package/StructId.Package.msbuildproj b/src/StructId.Package/StructId.Package.msbuildproj index 25a661d..cd7cd65 100644 --- a/src/StructId.Package/StructId.Package.msbuildproj +++ b/src/StructId.Package/StructId.Package.msbuildproj @@ -5,7 +5,8 @@ true Stronly typed ids using readonly record structs and modern C# features. dotnet record struct typed id - build + buildTransitive + true @@ -15,7 +16,7 @@ - + diff --git a/src/StructId.Package/StructId.props b/src/StructId.Package/StructId.props deleted file mode 100644 index 4de98b5..0000000 --- a/src/StructId.Package/StructId.props +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/src/StructId.Package/StructId.targets b/src/StructId.Package/StructId.targets index 3e8a234..3b4a04e 100644 --- a/src/StructId.Package/StructId.targets +++ b/src/StructId.Package/StructId.targets @@ -1,50 +1,21 @@ - - $(RootNamespace) - StructId - $([MSBuild]::StableStringHash($(StructIdNamespace)))\ - - - - + + + false + StructId\%(Filename)%(Extension) + + + + - - - - $(IntermediateOutputPath)%(Link) - - - - - - - - - %(FullPath) - - - - - - - $([System.IO.File]::ReadAllText(%(StructId.FullPath))) - $(StructIdContent.Replace('using StructId', 'using $(StructIdNamespace)').Replace('namespace StructId', 'namespace $(StructIdNamespace)')) - - - - $([MSBuild]::Unescape($(StructIdContent))) - - - - - - - - - + false @@ -62,29 +33,8 @@ - + - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/StructId.Tests/StructId.Tests.csproj b/src/StructId.Tests/StructId.Tests.csproj index 756b75c..dd5faaa 100644 --- a/src/StructId.Tests/StructId.Tests.csproj +++ b/src/StructId.Tests/StructId.Tests.csproj @@ -1,7 +1,5 @@  - - net8.0 enable