Skip to content

Commit 5a5d88b

Browse files
committed
improve System.Drawing support in the core library
1 parent 32a6a0d commit 5a5d88b

File tree

4 files changed

+139
-41
lines changed

4 files changed

+139
-41
lines changed

FastCloner.Contrib/ContribTypeHandlers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Register()
2424

2525
private static object ProcessFont(Type type, bool unboxStruct, FastClonerExprGenerator.ExpressionPosition position)
2626
{
27-
return (Func<object, FastCloneState, object>)((obj, state) =>
27+
return (Func<object, FastCloneState, object>)(static (obj, state) =>
2828
{
2929
Font font = (Font)obj;
3030
Font result = (Font)font.Clone();

FastCloner.Tests/FastCloner.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<PackageReference Include="FluentValidation" Version="12.0.0" />
1616
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1717
<PackageReference Include="NHibernate" Version="5.5.2" />
18-
<PackageReference Include="NUnit" Version="4.3.2" />
19-
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
20-
<PackageReference Include="NUnit.Analyzers" Version="4.9.2">
18+
<PackageReference Include="NUnit" Version="4.4.0" />
19+
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
20+
<PackageReference Include="NUnit.Analyzers" Version="4.10.0">
2121
<PrivateAssets>all</PrivateAssets>
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2323
</PackageReference>
@@ -26,7 +26,7 @@
2626
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2727
</PackageReference>
2828
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
29-
<PackageReference Include="System.Data.SQLite" Version="1.0.119" />
29+
<PackageReference Include="System.Data.SQLite" Version="2.0.1" />
3030
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
3131
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
3232
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />

FastCloner.Tests/SpecialCaseTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,4 +2960,67 @@ public void NonGenericDictionaryWithOptionalConstructor_ShouldDeepClone()
29602960
Assert.That(clone["key1"], Is.EqualTo(999), "Clone should reflect changes");
29612961
});
29622962
}
2963+
2964+
[Test]
2965+
public void Drawing_Image_DeepClone_Test()
2966+
{
2967+
// Arrange
2968+
Image original = new Bitmap(10, 10);
2969+
2970+
// Act
2971+
Image clone = original.DeepClone();
2972+
2973+
// Assert
2974+
Assert.Multiple(() =>
2975+
{
2976+
Assert.That(clone, Is.Not.SameAs(original));
2977+
Assert.That(clone.Width, Is.EqualTo(original.Width));
2978+
Assert.That(clone.Height, Is.EqualTo(original.Height));
2979+
});
2980+
}
2981+
2982+
[Test]
2983+
public void Drawing_Icon_DeepClone_Test()
2984+
{
2985+
// Arrange
2986+
using Bitmap bitmap = new Bitmap(16, 16);
2987+
using Graphics g = Graphics.FromImage(bitmap);
2988+
g.Clear(Color.Red);
2989+
IntPtr hIcon = bitmap.GetHicon();
2990+
Icon original = Icon.FromHandle(hIcon);
2991+
2992+
// Act
2993+
Icon clone = original.DeepClone();
2994+
2995+
// Assert
2996+
Assert.Multiple(() =>
2997+
{
2998+
Assert.That(clone, Is.Not.SameAs(original));
2999+
Assert.That(clone.Width, Is.EqualTo(original.Width));
3000+
Assert.That(clone.Height, Is.EqualTo(original.Height));
3001+
});
3002+
}
3003+
3004+
[Test]
3005+
public void Drawing_Brush_DeepClone_Test()
3006+
{
3007+
// Arrange
3008+
SolidBrush original = new SolidBrush(Color.Red);
3009+
3010+
// Act
3011+
SolidBrush clone = original.DeepClone();
3012+
3013+
// Assert
3014+
Assert.Multiple(() =>
3015+
{
3016+
Assert.That(clone, Is.Not.SameAs(original));
3017+
Assert.That((clone).Color.R, Is.EqualTo((original).Color.R));
3018+
Assert.That((clone).Color.G, Is.EqualTo((original).Color.G));
3019+
Assert.That((clone).Color.B, Is.EqualTo((original).Color.B));
3020+
Assert.That((clone).Color.A, Is.EqualTo((original).Color.A));
3021+
});
3022+
3023+
original.Color = Color.Blue;
3024+
Assert.That(clone.Color.B, Is.EqualTo(0));
3025+
}
29633026
}

0 commit comments

Comments
 (0)