Skip to content

Commit 5390e42

Browse files
committed
Implement MySqlAttribute.Clone. Fixes #1169
1 parent ccfd270 commit 5390e42

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

docs/content/api/MySqlConnector/MySqlAttribute/Clone.md

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlAttributeType.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MySqlConnector/MySqlAttribute.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace MySqlConnector
55
/// </summary>
66
/// <remarks>See <a href="https://dev.mysql.com/doc/refman/8.0/en/query-attributes.html">Query Attributes</a> for information on using query attributes.</remarks>
77
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
8-
public sealed class MySqlAttribute
8+
public sealed class MySqlAttribute : ICloneable
99
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
1010
{
1111
/// <summary>
@@ -35,6 +35,13 @@ public MySqlAttribute(string attributeName, object? value)
3535
/// </summary>
3636
public object? Value { get; set; }
3737

38+
/// <summary>
39+
/// Returns a new <see cref="MySqlAttribute"/> with the same property values as this instance.
40+
/// </summary>
41+
public MySqlAttribute Clone() => new MySqlAttribute(AttributeName, Value);
42+
43+
object ICloneable.Clone() => Clone();
44+
3845
internal MySqlParameter ToParameter()
3946
{
4047
if (string.IsNullOrEmpty(AttributeName))

tests/MySqlConnector.Tests/MySqlAttributeTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ public void ConstructWithArguments()
2727
Assert.Equal("name", attribute.AttributeName);
2828
Assert.Equal("value", attribute.Value);
2929
}
30+
31+
[Fact]
32+
public void Clone()
33+
{
34+
var attribute = new MySqlAttribute("name", "value");
35+
var clone = attribute.Clone();
36+
Assert.NotSame(attribute, clone);
37+
Assert.Equal(attribute.AttributeName, clone.AttributeName);
38+
Assert.Equal(attribute.Value, clone.Value);
39+
}
3040
}

tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</ItemGroup>
3333

3434
<ItemGroup Condition=" '$(Configuration)' == 'Baseline' ">
35-
<PackageReference Include="MySql.Data" Version="8.0.28" />
35+
<PackageReference Include="MySql.Data" Version="8.0.29" />
3636
<Compile Remove="ByteBufferWriterTests.cs;CachedProcedureTests.cs;CancellationTests.cs;ConnectionTests.cs;FakeMySqlServer.cs;FakeMySqlServerConnection.cs;LoadBalancerTests.cs;MySqlDecimalTests.cs;MySqlExceptionTests.cs;MySqlParameterCollectionNameToIndexTests.cs;NormalizeTests.cs;ServerVersionTests.cs;StatementPreparerTests.cs;TypeMapperTests.cs;UtilityTests.cs" />
3737
</ItemGroup>
3838

0 commit comments

Comments
 (0)