Skip to content

Commit d5dd958

Browse files
authored
Merge pull request #65 from seesharper/pass-null-to-converter-functions
Pass null to converter functions
2 parents 1ddab8f + 72a3eef commit d5dd958

File tree

11 files changed

+46
-19
lines changed

11 files changed

+46
-19
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Install .Net Core
1212
uses: actions/setup-dotnet@v2.0.0
1313
with:
14-
dotnet-version: 6.0.203
14+
dotnet-version: "7.0.200"
1515
- name: Install dotnet-script
1616
run: dotnet tool install dotnet-script --global
1717

.vscode/tasks.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"presentation": {
1414
"reveal": "always"
1515
},
16+
"options": {
17+
"cwd": "${workspaceFolder}"
18+
},
1619
"problemMatcher": "$msCompile"
1720
},
1821
{
@@ -29,6 +32,9 @@
2932
"reveal": "always",
3033
"clear": true
3134
},
35+
"options": {
36+
"cwd": "${workspaceFolder}"
37+
},
3238
"problemMatcher": "$msCompile"
3339
},
3440
{
@@ -60,7 +66,7 @@
6066
"type": "process",
6167
"args": [
6268
"script",
63-
"${workspaceFolder}/../build/build.csx",
69+
"${workspaceFolder}/build/build.csx",
6470
"testcoverage"
6571
],
6672
"problemMatcher": "$msCompile",

build/omnisharp.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

global.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.203"
3+
"version": "7.0.100",
4+
"rollForward": "latestFeature"
45
}
5-
}
6+
}

omnisharp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
},
1010
"script": {
1111
"enableScriptNuGetReferences": true,
12-
"defaultTargetFramework": "net6.0"
12+
"defaultTargetFramework": "net7.0"
1313
}
1414
}

src/DbReader.Tests/ArgumentParserMethodBuilderTests.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,23 @@ public void ShouldHandleEnumWithConverterFunction()
4444
[Fact]
4545
public void ShouldHandleNullableEnumWithoutConverterFunctionPassingNull()
4646
{
47-
var args = new { Status = new EnumParameterWithoutConverterFunction?() };
47+
//var args = new { EnumParameterWithoutConverterFunctionStatus = (EnumParameterWithoutConverterFunction?)null };
48+
var args = new Args() { Status = null };
4849
var method = argumentParserMethodBuilder.CreateMethod("@Status", args.GetType(), Array.Empty<IDataParameter>());
4950
var result = method("@Status", args, () => new TestDataParameter());
5051
result.Parameters[0].Value.ShouldBe(DBNull.Value);
5152
}
5253

54+
[Fact]
55+
public void ShouldHandleNullableEnumWithConverterFunctionPassingNull()
56+
{
57+
DbReaderOptions.WhenPassing<EnumParameterWithConverterFunctionPassingNull?>().Use((parameter, value) => parameter.Value = (int)EnumParameterWithConverterFunctionPassingNull.Value3);
58+
var args = new { Status = (EnumParameterWithConverterFunctionPassingNull?)null };
59+
var method = argumentParserMethodBuilder.CreateMethod("@Status", args.GetType(), Array.Empty<IDataParameter>());
60+
var result = method("@Status", args, () => new TestDataParameter());
61+
result.Parameters[0].Value.ShouldBe(3);
62+
}
63+
5364
[Fact]
5465
public void ShouldHandleNullableEnumWithoutConverterFunction()
5566
{
@@ -118,6 +129,15 @@ public class ThrowingDataParameter : IDataParameter
118129
public DataRowVersion SourceVersion { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
119130
public object Value { get => throw new NotImplementedException(); set => throw new ArgumentException(); }
120131
}
132+
133+
public enum EnumParameterWithConverterFunctionPassingNull
134+
{
135+
Value1 = 1,
136+
Value2 = 2,
137+
Value3 = 3
138+
}
139+
140+
121141
public enum EnumParameterWithoutConverterFunction
122142
{
123143
Value1 = 1,
@@ -131,7 +151,12 @@ public enum EnumParameterWithConverterFunction
131151
Value2 = 2,
132152
Value3 = 3
133153
}
154+
public class Args
155+
{
156+
public EnumParameterWithoutConverterFunction? Status { get; set; }
157+
}
134158
}
135159

136160

161+
137162
}

src/DbReader.Tests/DbReader.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<PackageReference Include="ILVerifier" Version="0.0.1" />
3030
</ItemGroup>
3131
<PropertyGroup>
32-
<TargetFrameworks>net6.0</TargetFrameworks>
32+
<TargetFrameworks>net7.0</TargetFrameworks>
3333
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
3434
</PropertyGroup>
3535
<ItemGroup>

src/DbReader.Tests/InstanceReaderVerificationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET6_0
1+
#if NET7_0
22
namespace DbReader.Tests
33
{
44
using System;

src/DbReader.Tests/VerifiableMethodSkeletonFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET6_0
1+
#if NET7_0
22
namespace DbReader.Tests
33
{
44
using System;

src/DbReader/ArgumentProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static ArgumentProcessor()
3434
ProcessDelegates.TryAdd(typeof(byte), (parameter, value) => AssignParameterValue(parameter, (byte)value));
3535
ProcessDelegates.TryAdd(typeof(short), (parameter, value) => AssignParameterValue(parameter, (short)value));
3636
ProcessDelegates.TryAdd(typeof(ushort), (parameter, value) => AssignParameterValue(parameter, (ushort)value));
37-
ProcessDelegates.TryAdd(typeof(ushort), (parameter, value) => AssignParameterValue(parameter, (ushort)value));
37+
ProcessDelegates.TryAdd(typeof(ushort), (parameter, value) => AssignParameterValue(parameter, (ushort)value));
3838
}
3939

4040

@@ -75,7 +75,7 @@ public static void RegisterProcessDelegate<TArgument>(Action<IDataParameter, TAr
7575

7676
public static void Process(Type argumentType, IDataParameter dataParameter, object argument)
7777
{
78-
if (argument == null)
78+
if (argument == null && !ProcessDelegates.ContainsKey(argumentType))
7979
{
8080
dataParameter.Value = DBNull.Value;
8181
return;

src/DbReader/DbReader.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net462</TargetFrameworks>
4+
<TargetFrameworks>net6.0;netstandard2.0;net462</TargetFrameworks>
55
<Authors>Bernhard Richter</Authors>
66
<PackageProjectUrl>https://github.com/seesharper/DbReader</PackageProjectUrl>
77
<RepositoryType>git</RepositoryType>
@@ -16,6 +16,7 @@
1616
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1717
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1818
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
19+
<LangVersion>latest</LangVersion>
1920
</PropertyGroup>
2021
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
2122
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
@@ -30,7 +31,7 @@
3031
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3132
</PackageReference>
3233
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
33-
<PackageReference Include="LightInject.Source" Version="6.5.1">
34+
<PackageReference Include="LightInject.Source" Version="6.6.4">
3435
<PrivateAssets>all</PrivateAssets>
3536
</PackageReference>
3637
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">

0 commit comments

Comments
 (0)