Skip to content

Commit 87fe687

Browse files
authored
Merge pull request #1665 from DapperLib/craver/dbstring-tostring
2 parents 42987a5 + b275d24 commit 87fe687

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Dapper/DbString.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public DbString()
4444
/// The value of the string
4545
/// </summary>
4646
public string Value { get; set; }
47+
48+
/// <summary>
49+
/// Gets a string representation of this DbString.
50+
/// </summary>
51+
public override string ToString() =>
52+
$"Dapper.DbString (Value: '{Value}', Length: {Length}, IsAnsi: {IsAnsi}, IsFixedLength: {IsFixedLength})";
53+
4754
/// <summary>
4855
/// Add the parameter to the command... internal use only
4956
/// </summary>

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Note: to get the latest pre-release build, add ` -Pre` to the end of the command
2727
- Parameters can now be re-used on subsequent commands (#952 via jamescrowley)
2828
- Array query support (`.Query<int[]>`) on supported platforms (e.g. Postgres) (#1598 via DarkWanderer)
2929
- `SqlMapper.HasTypeHandler` is made public for consumers (#1405 via brendangooden)
30-
- Improves multi-mapping error message when a specified column in splitOn can't be found (#1664 by NickCraver)
30+
- Improves multi-mapping error message when a specified column in splitOn can't be found (#1664 via NickCraver)
31+
- Improves DbString.ToString() (#1665 via NickCraver)
3132

3233
### 2.0.90
3334

tests/Dapper.Tests/MiscTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,24 @@ public void TestDbString()
655655
Assert.Equal(10, (int)obj.f);
656656
}
657657

658+
[Fact]
659+
public void TestDbStringToString()
660+
{
661+
Assert.Equal("Dapper.DbString (Value: 'abcde', Length: 10, IsAnsi: True, IsFixedLength: True)",
662+
new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = true }.ToString());
663+
Assert.Equal("Dapper.DbString (Value: 'abcde', Length: 10, IsAnsi: False, IsFixedLength: True)",
664+
new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = false }.ToString());
665+
Assert.Equal("Dapper.DbString (Value: 'abcde', Length: 10, IsAnsi: True, IsFixedLength: False)",
666+
new DbString { Value = "abcde", IsFixedLength = false, Length = 10, IsAnsi = true }.ToString());
667+
Assert.Equal("Dapper.DbString (Value: 'abcde', Length: 10, IsAnsi: False, IsFixedLength: False)",
668+
new DbString { Value = "abcde", IsFixedLength = false, Length = 10, IsAnsi = false }.ToString());
669+
670+
Assert.Equal("Dapper.DbString (Value: 'abcde', Length: -1, IsAnsi: True, IsFixedLength: False)",
671+
new DbString { Value = "abcde", IsAnsi = true }.ToString());
672+
Assert.Equal("Dapper.DbString (Value: 'abcde', Length: -1, IsAnsi: False, IsFixedLength: False)",
673+
new DbString { Value = "abcde", IsAnsi = false }.ToString());
674+
}
675+
658676
[Fact]
659677
public void TestDefaultDbStringDbType()
660678
{

0 commit comments

Comments
 (0)