Skip to content

Commit 245d3b0

Browse files
authored
Change all public types in namespace Cysharp.Text to internal (#372)
* Change all public types in namespace Cysharp.Text to internal * Regression caused by #368 * Stop namespace collision with Cysharp.Text nuget package * Affects: class, struct, interface, delegate, enum * using https://github.com/zzzprojects/findandreplace on command line, so we can automate this step: "fnr.exe" --cl --dir "SmartFormat.ZString\repo\src\ZString" --fileMask "*.cs,*.tt" --includeSubDirectories --caseSensitive --useRegEx --find "public (?=.*(class |struct |enum |interface |delegate ))" --replace "internal " * Add a unit test to get an alert when Cysharp.Text objects are public * Bump version to v3.3.2
1 parent d217ceb commit 245d3b0

43 files changed

Lines changed: 176 additions & 79 deletions

Some content is hidden

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

.github/workflows/SonarCloud.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
# (PRs from forks can't access secrets other than secrets.GITHUB_TOKEN for security reasons)
1414
if: ${{ !github.event.pull_request.head.repo.fork }}
1515
env:
16-
version: '3.3.1'
17-
versionFile: '3.3.1'
16+
version: '3.3.2'
17+
versionFile: '3.3.2'
1818
steps:
1919
- name: Set up JDK 17
2020
uses: actions/setup-java@v3

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for:
2323
- ps: dotnet restore SmartFormat.sln --verbosity quiet
2424
- ps: dotnet add .\SmartFormat.Tests\SmartFormat.Tests.csproj package AltCover
2525
- ps: |
26-
$version = "3.3.1"
26+
$version = "3.3.2"
2727
$versionFile = $version + "." + ${env:APPVEYOR_BUILD_NUMBER}
2828
2929
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<Copyright>Copyright 2011-$(CurrentYear) SmartFormat Project</Copyright>
99
<RepositoryUrl>https://github.com/axuno/SmartFormat.git</RepositoryUrl>
1010
<PublishRepositoryUrl>true</PublishRepositoryUrl>
11-
<Version>3.3.1</Version>
12-
<FileVersion>3.3.1</FileVersion>
11+
<Version>3.3.2</Version>
12+
<FileVersion>3.3.2</FileVersion>
1313
<AssemblyVersion>3.0.0</AssemblyVersion> <!--only update AssemblyVersion with major releases -->
1414
<LangVersion>latest</LangVersion>
1515
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Copyright SmartFormat Project maintainers and contributors.
3+
// Licensed under the MIT license.
4+
//
5+
6+
using NUnit.Framework;
7+
8+
namespace SmartFormat.ZString.Tests;
9+
10+
[TestFixture]
11+
public class CysharpText
12+
{
13+
/// <summary>
14+
/// To stop namespace collision with Cysharp.Text nuget package,
15+
/// change all public types in namespace Cysharp.Text to internal.
16+
/// This can easily happen when Cysharp.Text is updated in the SmartFormat.ZString project.
17+
/// Using https://github.com/zzzprojects/findandreplace on command line, so we can automate this step:
18+
/// "fnr.exe" --cl --dir "SmartFormat.ZString\repo\src\ZString" --fileMask "*.cs,*.tt" --includeSubDirectories --caseSensitive --useRegEx --find "public (?=.*(class |struct |enum |interface |delegate ))" --replace "internal "
19+
/// </summary>
20+
[Test]
21+
public void Classes_Of_Cysharp_Text_Namespace_Should_Be_Internal()
22+
{
23+
// If this tests fails, you need to run the above command line
24+
// to change all public types in namespace Cysharp.Text to internal
25+
Assert.Multiple(() =>
26+
{
27+
Assert.That(typeof(Cysharp.Text.Utf16ValueStringBuilder).IsPublic, Is.False);
28+
Assert.That(typeof(Cysharp.Text.Utf8ValueStringBuilder).IsPublic, Is.False);
29+
Assert.That(typeof(Cysharp.Text.ZString).IsPublic, Is.False);
30+
Assert.That(typeof(Cysharp.Text.FormatParser).IsPublic, Is.False);
31+
Assert.That(typeof(System.HexConverter).IsPublic, Is.False);
32+
});
33+
}
34+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Unit tests for SmartFormat.ZString</Description>
5+
<AssemblyTitle>SmartFormat.ZString.Tests</AssemblyTitle>
6+
<Authors>axuno gGmbH, Scott Rippey, Bernhard Millauer and other contributors.</Authors>
7+
<TargetFrameworks>net462;net6.0</TargetFrameworks>
8+
<DefineConstants>TRACE;DEBUG;RELEASE</DefineConstants>
9+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
10+
<AssemblyName>SmartFormat.ZString.Tests</AssemblyName>
11+
<AssemblyOriginatorKeyFile>../SmartFormat/SmartFormat.snk</AssemblyOriginatorKeyFile>
12+
<DelaySign>false</DelaySign>
13+
<SignAssembly>true</SignAssembly>
14+
<IsPackable>false</IsPackable>
15+
<Nullable>enable</Nullable>
16+
<NeutralLanguage>en</NeutralLanguage>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
22+
<PackageReference Include="NUnit" Version="4.0.1" />
23+
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
24+
<PrivateAssets>all</PrivateAssets>
25+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
</PackageReference>
27+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
28+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
29+
</ItemGroup>
30+
31+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
32+
<NoWarn>$(NoWarn);CA1861</NoWarn>
33+
<WarningLevel>4</WarningLevel>
34+
<DefineConstants>DEBUG;TRACE</DefineConstants>
35+
</PropertyGroup>
36+
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
38+
<NoWarn>$(NoWarn);CA1861</NoWarn>
39+
<WarningLevel>4</WarningLevel>
40+
<DefineConstants>RELEASE</DefineConstants>
41+
</PropertyGroup>
42+
43+
<ItemGroup>
44+
<ProjectReference Include="..\SmartFormat.ZString\SmartFormat.ZString.csproj" />
45+
</ItemGroup>
46+
47+
</Project>

src/SmartFormat.ZString/SmartFormat.ZString.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@
7979
<PackageReference Include="System.Memory" Version="4.5.4" />
8080
</ItemGroup>
8181

82+
<ItemGroup>
83+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
84+
<_Parameter1>SmartFormat.ZString.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a1cdb8ba81e1a00f0f9509a8f0c896e0de0da6875652fffd44fb867e6b78fd78c31c6fdb07544b2ae53ed4b56daa90333d32ac14387f7f68d39165da8f99b8c294c1cee1bcc4bbcbe2dd73879824b53708837f425e2bf5c7d2cf868de9548c44871888bf9db5cb425064dda4b17134f8e3b52e1f686315a1832043c7b58fb0ac</_Parameter1>
85+
</AssemblyAttribute>
86+
</ItemGroup>
87+
8288
</Project>

src/SmartFormat.ZString/ZStringWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ public sealed class ZStringWriter : TextWriter
2727
{
2828
private Utf16ValueStringBuilder sb;
2929
private bool isOpen;
30-
private UnicodeEncoding encoding;
30+
private UnicodeEncoding encoding = null!;
3131

3232
/// <summary>
3333
/// Creates a new instance using <see cref="CultureInfo.CurrentCulture"/> as format provider.
3434
/// </summary>
3535
public ZStringWriter() : this(CultureInfo.CurrentCulture)
3636
{
37+
sb = Cysharp.Text.ZString.CreateStringBuilder();
38+
isOpen = true;
3739
}
3840

3941
/// <summary>
4042
/// Creates a new instance with given format provider.
4143
/// </summary>
4244
public ZStringWriter(IFormatProvider formatProvider) : base(formatProvider)
4345
{
44-
sb = Cysharp.Text.ZString.CreateStringBuilder();
45-
isOpen = true;
4646
}
4747

4848
/// <summary>

src/SmartFormat.ZString/repo/src/ZString/FormatParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static class FormatParser
77
{
88
// {index[,alignment][:formatString]}
99

10-
public readonly ref struct ParseResult
10+
internal readonly ref struct ParseResult
1111
{
1212
public readonly int Index;
1313
public readonly ReadOnlySpan<char> FormatString;

src/SmartFormat.ZString/repo/src/ZString/IResettableBufferWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Cysharp.Text
77
{
8-
public interface IResettableBufferWriter<T> : IBufferWriter<T>
8+
internal interface IResettableBufferWriter<T> : IBufferWriter<T>
99
{
1010
void Reset();
1111
}

src/SmartFormat.ZString/repo/src/ZString/Number/BitOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace System.Numerics
1515
/// The methods use hardware intrinsics when available on the underlying platform,
1616
/// otherwise they use optimized software fallbacks.
1717
/// </summary>
18-
public static class BitOperations
18+
internal static class BitOperations
1919
{
2020
// C# no-alloc optimization that directly wraps the data section of the dll (similar to string constants)
2121
// https://github.com/dotnet/roslyn/pull/24621

0 commit comments

Comments
 (0)