Skip to content

Commit ae482ea

Browse files
committed
Extract values from static expressions (zspitz/ExpressionTreeToString#29)
1 parent 9ba6624 commit ae482ea

File tree

9 files changed

+26
-42
lines changed

9 files changed

+26
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,4 @@ _*
266266
# neither should the solution that references them
267267
/ExpressionTreeVisualizer.Dev.sln
268268

269+
/PostBuild

Debuggee/Debuggee.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net472;netstandard2.0;netcoreapp2.0</TargetFrameworks>
5-
<RootNamespace>ExpressionTreeVisualizer.Serialization</RootNamespace>
5+
<RootNamespace>ExpressionTreeVisualizer.Debuggee</RootNamespace>
66
<AssemblyName>ExpressionTreeVisualizer.Debuggee</AssemblyName>
77
<LangVersion>8.0</LangVersion>
88
<Nullable>enable</Nullable>
@@ -28,8 +28,8 @@
2828
</PropertyGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Include="ZSpitz.Util" Version="0.0.27" />
32-
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
31+
<PackageReference Include="ZSpitz.Util" Version="0.0.42" />
32+
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
3333
<Reference Include="Microsoft.VisualStudio.DebuggerVisualizers">
3434
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.DebuggerVisualizers.dll</HintPath>
3535
<Private>false</Private>
@@ -40,9 +40,7 @@
4040

4141
<Target Name="CopyPackageAssembliesToSubFolder" AfterTargets="ResolveReferences">
4242
<ItemGroup>
43-
<ReferenceCopyLocalPaths Condition=" '%(ReferenceCopyLocalPaths.NuGetPackageId)' != '' "
44-
Update="%(ReferenceCopyLocalPaths)"
45-
DestinationSubDirectory="ExpressionTreeVisualizer\" />
43+
<ReferenceCopyLocalPaths Condition=" '%(ReferenceCopyLocalPaths.NuGetPackageId)' != '' " Update="%(ReferenceCopyLocalPaths)" DestinationSubDirectory="ExpressionTreeVisualizer\" />
4644
</ItemGroup>
4745
</Target>
4846
</Project>

Package/Package.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
30+
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
3131
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
32-
<PackageReference Include="ZSpitz.Util" Version="0.0.27" />
33-
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.27" />
32+
<PackageReference Include="ZSpitz.Util" Version="0.0.42" />
33+
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.42" />
3434
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
3535
<PackageReference Include="MultiSelectTreeView" Version="1.0.9" />
3636
</ItemGroup>

PostBuild/PostBuild.csproj

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

Serialization/ExpressionNodeData.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections;
1414
using ZSpitz.Util;
1515
using static ZSpitz.Util.Functions;
16+
using ExpressionTreeToString;
1617

1718
namespace ExpressionTreeVisualizer.Serialization {
1819
[Serializable]
@@ -64,16 +65,18 @@ public class ExpressionNodeData {
6465
public string[] FactoryMethodNames => _factoryMethodNames;
6566

6667

67-
internal ExpressionNodeData(object o, (string aggregatePath, string pathFromParent) path, VisualizerData visualizerData, Dictionary<string, (int start, int length)> pathSpans, bool isParameterDeclaration = false, PropertyInfo? pi = null, string? parentWatchExpression = null) :
68+
internal ExpressionNodeData(object o, (string aggregatePath, string pathFromParent) path, VisualizerData visualizerData, ValueExtractor valueExtractor, Dictionary<string, (int start, int length)> pathSpans, bool isParameterDeclaration = false, PropertyInfo? pi = null, string? parentWatchExpression = null) :
6869
this(
6970
o, path,
7071
visualizerData.Config.Language,
72+
valueExtractor,
7173
pathSpans, isParameterDeclaration, pi, parentWatchExpression
7274
) { }
7375

7476
private ExpressionNodeData(
7577
object o, (string aggregatePath, string pathFromParent) path,
7678
string language,
79+
ValueExtractor valueExtractor,
7780
Dictionary<string, (int start, int length)> pathSpans, bool isParameterDeclaration = false, PropertyInfo? pi = null, string? parentWatchExpression = null
7881
) {
7982
var (aggregatePath, pathFromParent) = path;
@@ -107,32 +110,28 @@ private ExpressionNodeData(
107110
Closure = expressionType.Name;
108111
}
109112

110-
object? value = null;
113+
var (evaluated, value) = valueExtractor.GetValue(expr);
114+
if (evaluated) {
115+
StringValue = StringValue(value!, language); // TODO value is allowed to be null
116+
EnableValueInNewWindow = value is { } && value.GetType().InheritsFromOrImplementsAny(NodeTypes);
117+
}
111118

112119
// fill StringValue and EndNodeType properties, for expressions
113120
switch (expr) {
114121
case ConstantExpression cexpr when !cexpr.Type.IsClosureClass():
115-
value = cexpr.Value;
116122
EndNodeType = Constant;
117123
break;
118124
case ParameterExpression pexpr1:
119125
EndNodeType = Parameter;
120126
break;
121127
case Expression e1 when expr.IsClosedVariable():
122-
value = expr.ExtractValue();
123128
EndNodeType = ClosedVar;
124129
break;
125130
case DefaultExpression defexpr:
126-
value = defexpr.ExtractValue();
127131
EndNodeType = Default;
128132
break;
129133
}
130134

131-
if (value != null) {
132-
StringValue = StringValue(value, language);
133-
EnableValueInNewWindow = value.GetType().InheritsFromOrImplementsAny(NodeTypes);
134-
}
135-
136135
break;
137136
case MemberBinding mbind:
138137
NodeType = mbind.BindingType.ToString();
@@ -197,7 +196,7 @@ private ExpressionNodeData(
197196
.Where(x => x.x != null)
198197
.SelectT((relativePath, o1, prp) => new ExpressionNodeData(
199198
o1, (FullPath ?? "", relativePath),
200-
language, pathSpans,
199+
language, valueExtractor, pathSpans,
201200
false, prp, WatchExpressionFormatString))
202201
.ToList();
203202

Serialization/VisualizerData.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public VisualizerData(object o, Config? config = null) {
1818
o = ((Expression)ResolvePath(o, Config.Path)).ExtractValue();
1919
}
2020
Source = WriterBase.Create(o, Config.Formatter, Config.Language, out var pathSpans).ToString();
21-
Root = new ExpressionNodeData(o, ("", ""), this, pathSpans, false);
21+
22+
var valueExtractor = new ValueExtractor();
23+
Root = new ExpressionNodeData(o, ("", ""), this, valueExtractor, pathSpans, false);
2224
}
2325
}
2426
}

Tests.Visualizer/Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
12+
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
1313
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1414
<PackageReference Include="xunit" Version="2.4.1" />
1515
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
19-
<PackageReference Include="ExpressionTreeTestObjects" Version="1.0.2" />
19+
<PackageReference Include="ExpressionTreeTestObjects" Version="1.0.5" />
2020
</ItemGroup>
2121

2222
<ItemGroup>

Visualizer/Visualizer.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.DebuggerVisualizers.dll</HintPath>
1717
<Private>false</Private>
1818
</Reference>
19-
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
19+
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
2020
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2121
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
2222
<PackageReference Include="MultiSelectTreeView" Version="1.0.9" />
23-
<PackageReference Include="ZSpitz.Util" Version="0.0.27" />
24-
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.27" />
23+
<PackageReference Include="ZSpitz.Util" Version="0.0.42" />
24+
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.42" />
2525
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2626
<PackageReference Include="Octokit" Version="0.48.0" />
2727
<ProjectReference Include="..\Debuggee\Debuggee.csproj" />

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ only_commits:
1414
- Serialization/
1515
- UI/
1616
- Visualizer/
17-
- Visualizer.Xaml/
1817
- appveyor.yml
1918

2019
dotnet_csproj:

0 commit comments

Comments
 (0)