Skip to content

Commit

Permalink
Move common code to assemblies (dotnet#12506)
Browse files Browse the repository at this point in the history
Most of what was in the Common folder was only used in one place or could live in a shared assembly. Moved what I easily could.
  • Loading branch information
JeremyKuhne authored Nov 19, 2024
1 parent abad7ec commit 7896a6e
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 67 deletions.
12 changes: 0 additions & 12 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@
<RuntimeFrameworkVersion Condition="!$(TargetFramework.StartsWith('$(RedistTargetFrameworkName)'))" />
</PropertyGroup>

<Choose>
<When Condition="'$(IncludeInternalObsoleteAttribute)' == 'true' and '$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup>
<Compile Include="$(RepoRoot)src\Common\src\ObsoleteAttribute.cs" />
</ItemGroup>
<PropertyGroup>
<!-- Suppress CS0436 to allow ObsoleteAttribute to be internally defined and used in .NET Standard. -->
<NoWarn>$(NoWarn);CS0436</NoWarn>
</PropertyGroup>
</When>
</Choose>

<!-- If a tfm doesn't target .NETCoreApp but uses the platform support attributes, then we include the
System.Runtime.Versioning*Platform* annotation attribute classes in the project as internal.
Expand Down
24 changes: 0 additions & 24 deletions src/Common/src/HandleRefMarshaller.cs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 10 additions & 16 deletions src/System.Drawing.Common/src/System.Drawing.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@
<None Include="resources.targets" />
</ItemGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard'">
<IncludeInternalObsoleteAttribute>true</IncludeInternalObsoleteAttribute>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="**\*.cs" Exclude="Special\**\*.cs" />
<Compile Include="..\..\Common\src\LocalAppContextSwitches.Common.cs" Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="..\..\Common\src\ValueStringBuilder.cs" Link="System\Text\ValueStringBuilder.cs" />

<Content Include="NativeMethods.json" />
<Content Include="NativeMethods.txt" />
Expand All @@ -70,30 +63,31 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<Compile Include="..\..\Common\src\DisableRuntimeMarshalling.cs" Link="Common\DisableRuntimeMarshalling.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETStandard'">
<Compile Include="Special\Forwards.cs" />
</ItemGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard'">
<!-- Suppress CS0436 to allow ObsoleteAttribute to be internally defined and used in .NET Standard. -->
<NoWarn>$(NoWarn);CS0436</NoWarn>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
<Compile Include="Special\NotSupported.cs" />
<Compile Include="$(RepoRoot)src\Common\src\NullableAttributes.cs" />
<Compile Include="Special\NullableAttributes.cs" />
<Compile Include="Special\ObsoleteAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="..\..\Common\src\RequiresUnreferencedCodeAttribute.cs" Link="Common\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="..\..\Common\src\UnconditionalSuppressMessageAttribute.cs" Link="Common\UnconditionalSuppressMessageAttribute.cs" />
<Compile Include="Special\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="Special\UnconditionalSuppressMessageAttribute.cs" />
</ItemGroup>

<ItemGroup>
<Compile Include="Special\AssemblyRef.cs" />
</ItemGroup>

<Import Project="..\..\Shared\DrawingInterop\DrawingInterop.projitems" Label="Shared" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />

<Import Project="packaging.targets" />
<Import Project="resources.targets" />

Expand Down
4 changes: 1 addition & 3 deletions src/System.Drawing.Common/src/resources.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
GenerateSource="true"
ClassName="$(StringResourcesNamespace).$(StringResourcesClassName)" />
<!-- Include common SR helper when resources are included. -->
<Compile Include="$(RepoRoot)src/Common/src/SR$(DefaultLanguageSourceExtension)"
Visible="true"
Link="Resources/Common/SR$(DefaultLanguageSourceExtension)" />
<Compile Include="Special/SR$(DefaultLanguageSourceExtension)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace System.Text;

/// <summary>
/// String builder struct that allows using stack space for small strings.
/// </summary>
internal ref partial struct ValueStringBuilder
{
private char[]? _arrayToReturnToPool;
Expand Down Expand Up @@ -53,11 +56,14 @@ public void EnsureCapacity(int capacity)
}

/// <summary>
/// Get a pinnable reference to the builder.
/// Does not ensure there is a null char after <see cref="Length"/>
/// This overload is pattern matched in the C# 7.3+ compiler so you can omit
/// the explicit method call, and write eg "fixed (char* c = builder)"
/// Get a pinnable reference to the builder. Does not ensure there is a null char after <see cref="Length"/>
/// </summary>
/// <remarks>
/// <para>
/// This overload is pattern matched in the C# 7.3+ compiler so you can omit
/// the explicit method call, and write eg "fixed (char* c = builder)"
/// </para>
/// </remarks>
public readonly ref char GetPinnableReference() => ref MemoryMarshal.GetReference(_chars);

/// <summary>
Expand Down Expand Up @@ -91,11 +97,13 @@ public override string ToString()
return s;
}

/// <summary>Returns the underlying storage of the builder.</summary>
/// <summary>
/// Returns the underlying storage of the builder.
/// </summary>
public readonly Span<char> RawChars => _chars;

/// <summary>
/// Returns a span around the contents of the builder.
/// Returns a span around the contents of the builder.
/// </summary>
/// <param name="terminate">Ensures that the builder has a null char after <see cref="Length"/></param>
public ReadOnlySpan<char> AsSpan(bool terminate)
Expand Down Expand Up @@ -186,8 +194,9 @@ public void Append(string? s)
}

int pos = _pos;
if (s.Length == 1 && (uint)pos < (uint)_chars.Length) // very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc.
if (s.Length == 1 && (uint)pos < (uint)_chars.Length)
{
// Very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc.
_chars[pos] = s[0];
_pos = pos + 1;
}
Expand Down Expand Up @@ -275,12 +284,12 @@ private void GrowAndAppend(char c)
}

/// <summary>
/// Resize the internal buffer either by doubling current buffer size or
/// by adding <paramref name="additionalCapacityBeyondPos"/> to
/// Resize the internal buffer either by doubling current buffer size or
/// by adding <paramref name="additionalCapacityBeyondPos"/> to
/// <see cref="_pos"/> whichever is greater.
/// </summary>
/// <param name="additionalCapacityBeyondPos">
/// Number of chars requested beyond current position.
/// Number of chars requested beyond current position.
/// </param>
[MethodImpl(MethodImplOptions.NoInlining)]
private void Grow(int additionalCapacityBeyondPos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\Common\src\WeakRefCollection.cs" Link="System\Collections\Generic\WeakRefCollection.cs" />
<Compile Include="..\..\System.Windows.Forms.Analyzers\src\System\Windows\Forms\Analyzers\Diagnostics\DiagnosticIDs.cs" Link="System\Windows\Forms\Analyzers\Diagnostics\DiagnosticIDs.cs" />
</ItemGroup>

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/System.Windows.Forms/src/System.Windows.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\Common\src\IComparerHelpers.cs" Link="Common\IComparerHelpers.cs" />
<Compile Include="..\..\Common\src\Obsoletions.cs" Link="Common\Obsoletions.cs" />
<Compile Include="..\..\Common\src\RTLAwareMessageBox.cs" Link="Common\RTLAwareMessageBox.cs" />
</ItemGroup>
Expand Down
File renamed without changes.

0 comments on commit 7896a6e

Please sign in to comment.