Skip to content

Commit 60a9297

Browse files
authored
Merge/2 (#3)
* fix vs2017 text explorer bug (load multiple adapters) * Support null filtering with strings * Bump to version 1.0.1
1 parent 69314d9 commit 60a9297

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

src/StringToExpression/StringToExpression.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Out of the box configuration is provided for parsing arithmetic expressions and
1212
<PackageProjectUrl>https://github.com/codecutout/StringToExpression</PackageProjectUrl>
1313
<PackageTags>Expression Filter OData Arithmetic DSL</PackageTags>
1414
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
15+
<Version>1.0.1</Version>
1516
</PropertyGroup>
1617

1718
</Project>

src/StringToExpression/Util/ExpressionConversions.cs

+21-4
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,30 @@ public static bool TryImplicitlyConvert(ref Expression exp1, ref Expression exp2
103103
}
104104
else if (IsNullConstant(exp1))
105105
{
106-
//one of our expressions is null, so convert the other side to a nullable
107-
commonType = typeof(Nullable<>).MakeGenericType(type2);
106+
// strings are already nullables
107+
if (type2 == typeof(string))
108+
{
109+
commonType = type2;
110+
}
111+
else
112+
{
113+
//one of our expressions is null, so convert the other side to a nullable
114+
commonType = typeof(Nullable<>).MakeGenericType(type2);
115+
}
108116
}
109117
else if (IsNullConstant(exp2))
110118
{
111-
//the other side of the expression is null so convert the first side to a nullable
112-
commonType = typeof(Nullable<>).MakeGenericType(type1);
119+
// strings are already nullables
120+
if (type1 == typeof(string))
121+
{
122+
commonType = type1;
123+
}
124+
else
125+
{
126+
//the other side of the expression is null so convert the first side to a nullable
127+
commonType = typeof(Nullable<>).MakeGenericType(type1);
128+
}
129+
113130
}
114131
else if (TryGetCommonType(type1, type2, out commonType))
115132
{

tests/StringToExpression.Test/Languages/ODataFilter/Fixtures/LinqToQuerystringTestDataFixture.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public LinqToQuerystringTestDataFixture()
8787
NullableCollection = new List<NullableClass>
8888
{
8989
InstanceBuilders.BuildNull(),
90-
InstanceBuilders.BuildNull(1, new DateTime(2002, 01, 01), true, 10000000000, 111.111, 111.111f, 0x00, guidArray[0])
90+
InstanceBuilders.BuildNull(1, new DateTime(2002, 01, 01), true, 10000000000, 111.111, 111.111f, 0x00, guidArray[0], "Dogfood")
9191
}.AsQueryable();
9292
}
9393

@@ -113,9 +113,9 @@ public static NullableClass BuildNull()
113113
return new NullableClass();
114114
}
115115

116-
public static NullableClass BuildNull(int? age, DateTime? date, bool? complete, long? population, double? value, float? cost, byte? code, Guid? guid)
116+
public static NullableClass BuildNull(int? age, DateTime? date, bool? complete, long? population, double? value, float? cost, byte? code, Guid? guid, string name)
117117
{
118-
return new NullableClass { Date = date, Age = age, Complete = complete, Population = population, Value = value, Cost = cost, Code = code, Guid = guid };
118+
return new NullableClass { Date = date, Age = age, Complete = complete, Population = population, Value = value, Cost = cost, Code = code, Guid = guid, Name = name };
119119
}
120120
}
121121

@@ -201,6 +201,8 @@ public class NullableClass
201201
{
202202
public int? Id { get; set; }
203203

204+
public string Name { get; set; }
205+
204206
public DateTime? Date { get; set; }
205207

206208
public int? Age { get; set; }

tests/StringToExpression.Test/Languages/ODataFilter/LinqToQuerystringEquivalenceTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ public void When_edgecase_data_should_return_same_results_as_linqToQuerystring(s
209209
[InlineData("Cost eq 111.111f")]
210210
[InlineData("Code eq 0x00")]
211211
[InlineData("Guid eq guid'" + LinqToQuerystringTestDataFixture.guid0 + "'")]
212+
[InlineData("Name eq null")]
213+
[InlineData("null eq Name")]
214+
[InlineData("Name ne null")]
215+
[InlineData("null ne Name")]
212216
public void When_nullable_data_should_return_same_results_as_linqToQuerystring(string query)
213217
{
214218
var linqToQuerystringFiltered = Data.NullableCollection.LinqToQuerystring("?$filter=" + query).ToList();

tests/StringToExpression.Test/StringToExpression.Test.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ItemGroup>
88
<PackageReference Include="LinqToQuerystring" Version="0.7.0.8" />
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
10-
<PackageReference Include="xunit" Version="2.2.0" />
11-
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
10+
<PackageReference Include="xunit" Version="2.3.1" />
11+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)