diff --git a/Dapper/SqlMapper.cs b/Dapper/SqlMapper.cs index 8f3956cab..61ca69329 100644 --- a/Dapper/SqlMapper.cs +++ b/Dapper/SqlMapper.cs @@ -2601,12 +2601,12 @@ private static bool IsValueTuple(Type? type) => (type?.IsValueType == true var allTypeProps = type.GetProperties(); var propsList = new List(allTypeProps.Length); - for (int i = 0; i < allTypeProps.Length; ++i) - { - var p = allTypeProps[i]; - if (p.GetIndexParameters().Length == 0) - propsList.Add(p); - } + for (int i = 0; i < allTypeProps.Length; ++i) + { + var p = allTypeProps[i]; + if (p.GetIndexParameters().Length == 0 && p.GetMethod?.IsStatic != true) + propsList.Add(p); + } var ctors = type.GetConstructors(); ParameterInfo[] ctorParams; diff --git a/Directory.Packages.props b/Directory.Packages.props index 2f91a3cca..8f2772419 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -35,6 +35,7 @@ + diff --git a/tests/Dapper.Tests/Dapper.Tests.csproj b/tests/Dapper.Tests/Dapper.Tests.csproj index 93b498618..09947a89a 100644 --- a/tests/Dapper.Tests/Dapper.Tests.csproj +++ b/tests/Dapper.Tests/Dapper.Tests.csproj @@ -31,8 +31,9 @@ - - + + + diff --git a/tests/Dapper.Tests/FakeDbTests.Issue621.cs b/tests/Dapper.Tests/FakeDbTests.Issue621.cs new file mode 100644 index 000000000..2c949b186 --- /dev/null +++ b/tests/Dapper.Tests/FakeDbTests.Issue621.cs @@ -0,0 +1,31 @@ +#if !NET481 +using pengdows.crud.fakeDb; +using Xunit; + +namespace Dapper.Tests +{ + public sealed class FakeDbIssue621Tests + { + [Fact] + public void StaticPropertiesAreIgnoredWhenCreatingParameters() + { + using var conn = new fakeDbConnection(new FakeDataStore()); + conn.EnqueueNonQueryResult(1); + conn.Open(); + + var parameters = new Parameters { InstanceValue = "instance" }; + Parameters.StaticValue = "static"; + + var result = conn.Execute("select @InstanceValue, @StaticValue", parameters); + + Assert.Equal(1, result); + } + + private sealed class Parameters + { + public string? InstanceValue { get; set; } + public static string? StaticValue { get; set; } + } + } +} +#endif