Skip to content

Commit

Permalink
Extract values from static expressions (zspitz/ExpressionTreeToString#29
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zspitz committed Jul 19, 2020
1 parent 9ba6624 commit ae482ea
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,4 @@ _*
# neither should the solution that references them
/ExpressionTreeVisualizer.Dev.sln

/PostBuild
10 changes: 4 additions & 6 deletions Debuggee/Debuggee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net472;netstandard2.0;netcoreapp2.0</TargetFrameworks>
<RootNamespace>ExpressionTreeVisualizer.Serialization</RootNamespace>
<RootNamespace>ExpressionTreeVisualizer.Debuggee</RootNamespace>
<AssemblyName>ExpressionTreeVisualizer.Debuggee</AssemblyName>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -28,8 +28,8 @@
</PropertyGroup>

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

<Target Name="CopyPackageAssembliesToSubFolder" AfterTargets="ResolveReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Condition=" '%(ReferenceCopyLocalPaths.NuGetPackageId)' != '' "
Update="%(ReferenceCopyLocalPaths)"
DestinationSubDirectory="ExpressionTreeVisualizer\" />
<ReferenceCopyLocalPaths Condition=" '%(ReferenceCopyLocalPaths.NuGetPackageId)' != '' " Update="%(ReferenceCopyLocalPaths)" DestinationSubDirectory="ExpressionTreeVisualizer\" />
</ItemGroup>
</Target>
</Project>
6 changes: 3 additions & 3 deletions Package/Package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="ZSpitz.Util" Version="0.0.27" />
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.27" />
<PackageReference Include="ZSpitz.Util" Version="0.0.42" />
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.42" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="MultiSelectTreeView" Version="1.0.9" />
</ItemGroup>
Expand Down
15 changes: 0 additions & 15 deletions PostBuild/PostBuild.csproj

This file was deleted.

21 changes: 10 additions & 11 deletions Serialization/ExpressionNodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections;
using ZSpitz.Util;
using static ZSpitz.Util.Functions;
using ExpressionTreeToString;

namespace ExpressionTreeVisualizer.Serialization {
[Serializable]
Expand Down Expand Up @@ -64,16 +65,18 @@ public class ExpressionNodeData {
public string[] FactoryMethodNames => _factoryMethodNames;


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) :
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) :
this(
o, path,
visualizerData.Config.Language,
valueExtractor,
pathSpans, isParameterDeclaration, pi, parentWatchExpression
) { }

private ExpressionNodeData(
object o, (string aggregatePath, string pathFromParent) path,
string language,
ValueExtractor valueExtractor,
Dictionary<string, (int start, int length)> pathSpans, bool isParameterDeclaration = false, PropertyInfo? pi = null, string? parentWatchExpression = null
) {
var (aggregatePath, pathFromParent) = path;
Expand Down Expand Up @@ -107,32 +110,28 @@ private ExpressionNodeData(
Closure = expressionType.Name;
}

object? value = null;
var (evaluated, value) = valueExtractor.GetValue(expr);
if (evaluated) {
StringValue = StringValue(value!, language); // TODO value is allowed to be null
EnableValueInNewWindow = value is { } && value.GetType().InheritsFromOrImplementsAny(NodeTypes);
}

// fill StringValue and EndNodeType properties, for expressions
switch (expr) {
case ConstantExpression cexpr when !cexpr.Type.IsClosureClass():
value = cexpr.Value;
EndNodeType = Constant;
break;
case ParameterExpression pexpr1:
EndNodeType = Parameter;
break;
case Expression e1 when expr.IsClosedVariable():
value = expr.ExtractValue();
EndNodeType = ClosedVar;
break;
case DefaultExpression defexpr:
value = defexpr.ExtractValue();
EndNodeType = Default;
break;
}

if (value != null) {
StringValue = StringValue(value, language);
EnableValueInNewWindow = value.GetType().InheritsFromOrImplementsAny(NodeTypes);
}

break;
case MemberBinding mbind:
NodeType = mbind.BindingType.ToString();
Expand Down Expand Up @@ -197,7 +196,7 @@ private ExpressionNodeData(
.Where(x => x.x != null)
.SelectT((relativePath, o1, prp) => new ExpressionNodeData(
o1, (FullPath ?? "", relativePath),
language, pathSpans,
language, valueExtractor, pathSpans,
false, prp, WatchExpressionFormatString))
.ToList();

Expand Down
4 changes: 3 additions & 1 deletion Serialization/VisualizerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public VisualizerData(object o, Config? config = null) {
o = ((Expression)ResolvePath(o, Config.Path)).ExtractValue();
}
Source = WriterBase.Create(o, Config.Formatter, Config.Language, out var pathSpans).ToString();
Root = new ExpressionNodeData(o, ("", ""), this, pathSpans, false);

var valueExtractor = new ValueExtractor();
Root = new ExpressionNodeData(o, ("", ""), this, valueExtractor, pathSpans, false);
}
}
}
4 changes: 2 additions & 2 deletions Tests.Visualizer/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ExpressionTreeTestObjects" Version="1.0.2" />
<PackageReference Include="ExpressionTreeTestObjects" Version="1.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Visualizer/Visualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.DebuggerVisualizers.dll</HintPath>
<Private>false</Private>
</Reference>
<PackageReference Include="ExpressionTreeToString" Version="2.0.20" />
<PackageReference Include="ExpressionTreeToString" Version="2.0.27" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="MultiSelectTreeView" Version="1.0.9" />
<PackageReference Include="ZSpitz.Util" Version="0.0.27" />
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.27" />
<PackageReference Include="ZSpitz.Util" Version="0.0.42" />
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.42" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Octokit" Version="0.48.0" />
<ProjectReference Include="..\Debuggee\Debuggee.csproj" />
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ only_commits:
- Serialization/
- UI/
- Visualizer/
- Visualizer.Xaml/
- appveyor.yml

dotnet_csproj:
Expand Down

0 comments on commit ae482ea

Please sign in to comment.