Skip to content

Commit a0d7700

Browse files
committed
feat: v4 with the new ResxSettingsAttribute
BREAKING CHANGE: none I hope, but adding this line will release v4 - Enjoy
1 parent 781e22d commit a0d7700

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1908
-200
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<RootNamespace>Catglobe.ResXFileCodeGenerator</RootNamespace>
7+
<IsPackable>false</IsPackable>
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//using System;
2+
3+
//namespace Catglobe.ResXFileCodeGenerator;
4+
5+
///// <summary>
6+
///// Attribute to set the inner class name and visibility for resx code generator.
7+
///// </summary>
8+
//[AttributeUsage(AttributeTargets.Enum, Inherited = false, AllowMultiple = false)]
9+
//[System.Diagnostics.Conditional("ResxSettingsAttribute_NEVER")]
10+
//public class ResxEnumSettingsAttribute : Attribute
11+
//{
12+
// /// <summary>
13+
// /// Set the prefix of the enum resource class.
14+
// /// </summary>
15+
// public string? Prefix { get; set; }
16+
// /// <summary>
17+
// /// Set the postfix of the enum resource class.
18+
// /// </summary>
19+
// public string? Postfix { get; set; }
20+
21+
// /// <summary>
22+
// /// Set if the class should have static members.
23+
// /// </summary>
24+
// public bool StaticMembers { get; set; } = true;
25+
//}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace Catglobe.ResXFileCodeGenerator;
4+
5+
/// <summary>
6+
/// Attribute force generation of matching resx files to this class instead of a class matching the filename.
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
9+
[System.Diagnostics.Conditional("ResxSettingsAttribute_NEVER")]
10+
public class ResxSettingsAttribute() : Attribute
11+
{
12+
/// <summary>
13+
/// Set if the class should have static members. Default is true.
14+
/// </summary>
15+
public bool StaticMembers { get; set; } = true;
16+
/// <summary>
17+
/// Set the visibility of the members. Default is private.
18+
/// </summary>
19+
public Visibility MembersVisibility { get; set; } = Visibility.Private;
20+
21+
/// <summary>
22+
/// Set if it should add a helper to get translations for Enum members of the given type
23+
/// </summary>
24+
public Type? ForEnum { get; set; }
25+
}
26+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Catglobe.ResXFileCodeGenerator;
2+
3+
public enum Visibility
4+
{
5+
NotSet = -1,
6+
NotGenerated = 0,
7+
Public,
8+
Internal,
9+
Private,
10+
Protected,
11+
SameAsOuter
12+
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
namespace Catglobe.ResXFileCodeGenerator.Tests;
22

3-
internal class AdditionalTextStub : AdditionalText
3+
internal class AdditionalTextStub(string path, string? text = null) : AdditionalText
44
{
5-
private readonly SourceText? _text;
5+
private readonly SourceText? _text = text is null ? null : SourceText.From(text, checksumAlgorithm: SourceHashAlgorithm.Sha256);
66

7-
public override string Path { get; }
8-
9-
public AdditionalTextStub(string path, string? text = null)
10-
{
11-
_text = text is null ? null : SourceText.From(text);
12-
Path = path;
13-
}
7+
public override string Path { get; } = path;
148

159
public override SourceText? GetText(CancellationToken cancellationToken = new()) => _text;
1610
}

Catglobe.ResXFileCodeGenerator.Tests/Catglobe.ResXFileCodeGenerator.Tests.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<LangVersion>latest</LangVersion>
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>enable</ImplicitUsings>
9+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
910
</PropertyGroup>
1011

1112
<Import Project="../Catglobe.ResXFileCodeGenerator/build/Catglobe.ResXFileCodeGenerator.props" />
@@ -32,12 +33,19 @@
3233
<EmbeddedResource Update="**/*.??.resx;**/*.??-??.resx">
3334
<DependentUpon>$([System.IO.Path]::GetFileNameWithoutExtension('%(FileName)')).resx</DependentUpon>
3435
</EmbeddedResource>
35-
<EmbeddedResource Update="IntegrationTests\Test2.resx">
36-
<UseResManager>true</UseResManager>
36+
<EmbeddedResource Update="IntegrationTests\**\*.resx">
37+
<UseResManager>true</UseResManager>
38+
</EmbeddedResource>
39+
<EmbeddedResource Update="IntegrationTests\Test1.resx">
40+
<UseResManager>false</UseResManager>
41+
</EmbeddedResource>
42+
<EmbeddedResource Update="IntegrationTests\TestDaWhenDaDk2.resx">
43+
<UseResManager>false</UseResManager>
3744
</EmbeddedResource>
3845
</ItemGroup>
3946

4047
<ItemGroup>
48+
<ProjectReference Include="..\Catglobe.ResXFileCodeGenerator.Attributes\Catglobe.ResXFileCodeGenerator.Attributes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
4149
<ProjectReference Include="..\Catglobe.ResXFileCodeGenerator\Catglobe.ResXFileCodeGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
4250
</ItemGroup>
4351
</Project>

Catglobe.ResXFileCodeGenerator.Tests/CodeGenTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private static void Generate(
224224
// ------------------------------------------------------------------------------
225225
#nullable enable
226226
namespace Resources;
227-
using static Catglobe.ResXFileCodeGenerator.Helpers;
227+
using static global::Catglobe.ResXFileCodeGenerator.Helpers;
228228
229229
{(publicClass ? "public" : "internal")}{(partial ? " partial" : string.Empty)}{(staticClass ? " static" : string.Empty)} class ActivityEntrySortRuleNames
230230
{{

Catglobe.ResXFileCodeGenerator.Tests/GeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static void GenerateInner(
138138
bool nullForgivingOperators = false,
139139
bool staticMembers = true,
140140
string innerClassName = "inner",
141-
InnerClassVisibility innerClassVisibility = InnerClassVisibility.SameAsOuter,
141+
Visibility innerClassVisibility = Visibility.SameAsOuter,
142142
string innerClassInstanceName = ""
143143
)
144144
{

Catglobe.ResXFileCodeGenerator.Tests/GroupResxFilesTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ public void CompareResxGroup_SameRoot_SameSubFiles_DifferentOrder()
2020
v1.ShouldBe(v2);
2121
}
2222

23+
[Fact]
24+
public void CompareResxGroup_SameRoot_SameSubFiles_DifferentOrder_DiffContent()
25+
{
26+
var v1 = new ResxGroup([
27+
ResxFile.From(new AdditionalTextStub(@"D:\src\xhg\y\Areas\CaModule\Pages\IdfgControlCenter.resx", "a"))!,
28+
ResxFile.From(new AdditionalTextStub(@"D:\src\xhg\y\Areas\CaModule\Pages\IdfgControlCenter.da.resx", "a"))!,
29+
ResxFile.From(new AdditionalTextStub(@"D:\src\xhg\y\Areas\CaModule\Pages\IdfgControlCenter.vi.resx", "a"))!,
30+
]);
31+
32+
var v2 = new ResxGroup([
33+
ResxFile.From(new AdditionalTextStub(@"D:\src\xhg\y\Areas\CaModule\Pages\IdfgControlCenter.resx", "a"))!,
34+
ResxFile.From(new AdditionalTextStub(@"D:\src\xhg\y\Areas\CaModule\Pages\IdfgControlCenter.vi.resx", "a"))!,
35+
ResxFile.From(new AdditionalTextStub(@"D:\src\xhg\y\Areas\CaModule\Pages\IdfgControlCenter.da.resx", "b"))!,
36+
]);
37+
38+
v1.ShouldNotBe(v2);
39+
}
40+
2341
[Fact]
2442
public void CompareResxGroup_SameRoot_DiffSubFilesNames()
2543
{

Catglobe.ResXFileCodeGenerator.Tests/HelperGeneratorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void CanGenerateCombo()
1212
ResxFile.From(new AdditionalTextStub("test.resx", ""))!,
1313
ResxFile.From(new AdditionalTextStub("test.da.resx", ""))!,
1414
ResxFile.From(new AdditionalTextStub("test.da-dk.resx", ""))!,
15-
]).SubFiles.CultureInfos),
15+
]).SubFiles),
1616
cancellationToken: default
1717
);
1818
var expected = @"// ------------------------------------------------------------------------------
@@ -42,7 +42,7 @@ internal static partial class Helpers
4242
[Fact]
4343
public void CanGenerateEmptyCombo()
4444
{
45-
var (generatedFileName, sourceCode, errorsAndWarnings) = new StringBuilderGenerator().Generate(new CultureInfoCombo([]), default);
45+
var (generatedFileName, sourceCode, errorsAndWarnings) = new StringBuilderGenerator().Generate(new(ImmutableEquatableArray<ResxFile>.Empty), default);
4646
var expected = @"// ------------------------------------------------------------------------------
4747
// <auto-generated>
4848
// This code was generated by a tool.

0 commit comments

Comments
 (0)