Skip to content

Commit 0ebbbe2

Browse files
authored
v4.1.3 release (#143)
* Fixing binary opeand type-is checks, re: #142 * v4.1.3 package --------- Co-authored-by: Steve Wilkes <[email protected]>
1 parent 9e44d6f commit 0ebbbe2

8 files changed

+179
-159
lines changed
Binary file not shown.
Binary file not shown.

src/ReadableExpressions/ReadableExpressions.csproj

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.0' ">1.6.1</NetStandardImplicitPackageVersion>
1515
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.0' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
1616

17-
<AssemblyVersion>4.1.2.0</AssemblyVersion>
18-
<FileVersion>4.1.2.0</FileVersion>
19-
<VersionPrefix>4.1.2</VersionPrefix>
20-
<Version>4.1.2</Version>
17+
<AssemblyVersion>4.1.3.0</AssemblyVersion>
18+
<FileVersion>4.1.3.0</FileVersion>
19+
<VersionPrefix>4.1.3</VersionPrefix>
20+
<Version>4.1.3</Version>
2121

2222
<PackageId>AgileObjects.ReadableExpressions</PackageId>
2323
<Title>AgileObjects.ReadableExpressions</Title>
@@ -26,10 +26,7 @@
2626
<PackageIcon>./Icon.png</PackageIcon>
2727
<PackageTags>ExpressionTrees Debugging DebuggerVisualizers Linq DLR</PackageTags>
2828
<PackageProjectUrl>https://github.com/AgileObjects/ReadableExpressions</PackageProjectUrl>
29-
<PackageReleaseNotes>- Fixing nullable enum translation, re: #134
30-
- Improving ShowCapturedValues capabilities to include captured Linq calls, re: #133
31-
- Fixing parameterless Value Tuple translation, re: #135
32-
- Fixing non-equality enum comparisons, re: #136
29+
<PackageReleaseNotes>- Fixing binary operand type-is checks, re: #142
3330
</PackageReleaseNotes>
3431
<PackageReadmeFile>README.md</PackageReadmeFile>
3532
<PackageOutputPath>../../NuGet</PackageOutputPath>

src/ReadableExpressions/Translations/BinaryTranslation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private static bool IsEnumType(
194194
Expression expression,
195195
out Expression enumExpression)
196196
{
197-
if (expression.NodeType.IsCast())
197+
if (expression.NodeType.IsConversion())
198198
{
199199
expression = expression.GetUnaryOperand();
200200
}

src/ReadableExpressions/Translations/CastTranslation.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,20 @@ public static bool IsCast(ExpressionType nodeType)
129129
{
130130
return nodeType switch
131131
{
132-
ExpressionType.Convert => true,
133-
ConvertChecked => true,
134132
TypeAs => true,
135133
TypeIs => true,
136134
Unbox => true,
135+
_ when IsConversion(nodeType) => true,
136+
_ => false
137+
};
138+
}
139+
140+
public static bool IsConversion(ExpressionType nodeType)
141+
{
142+
return nodeType switch
143+
{
144+
ExpressionType.Convert => true,
145+
ConvertChecked => true,
137146
_ => false
138147
};
139148
}

src/ReadableExpressions/Translations/TranslationExtensions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public static bool IsCast(this INodeTranslation translation)
4949
public static bool IsCast(this ExpressionType nodeType)
5050
=> CastTranslation.IsCast(nodeType);
5151

52+
public static bool IsConversion(this ExpressionType nodeType)
53+
=> CastTranslation.IsConversion(nodeType);
54+
5255
public static INodeTranslation WithParentheses(
5356
this INodeTranslation translation)
5457
{

src/Tests/ReadableExpressions.UnitTests/WhenTranslatingConversions.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ public void ShouldTranslateAnAsCastExpression()
9494
translated.ShouldBe("stream as IDisposable");
9595
}
9696

97+
[Fact]
98+
public void ShouldTranslateAnIsTypeExpression()
99+
{
100+
var objectIsDisposable = CreateLambda((object o) => o is IDisposable);
101+
102+
var translated = objectIsDisposable.Body.ToReadableString();
103+
104+
translated.ShouldBe("o is IDisposable");
105+
}
106+
107+
// See https://github.com/agileobjects/ReadableExpressions/issues/142
108+
[Fact]
109+
public void ShouldTranslateAnIsTypeExpressionOperand()
110+
{
111+
var intValueAndIsTypeChecks =
112+
CreateLambda((int i, object o) => i == 1 && o is string);
113+
114+
var translated = intValueAndIsTypeChecks.Body.ToReadableString();
115+
116+
translated.ShouldBe("(i == 1) && (o is string)");
117+
}
118+
97119
[Fact]
98120
public void ShouldTranslateABoxingExpression()
99121
{
@@ -168,7 +190,7 @@ public void ShouldTranslateExplicitUnaryConversionWithCustomStaticMethod()
168190
typeof(bool),
169191
typeof(Convert).GetMethod("IsDBNull")));
170192

171-
var translated =
193+
var translated =
172194
objectToBoolWithIsDbNullLambda.ToReadableString();
173195

174196
translated.ShouldBe("() => Convert.IsDBNull(null)");

0 commit comments

Comments
 (0)