Skip to content

Commit c2b13c0

Browse files
authored
Releases/3.0 (#85)
* Features/build project (#80) * Remvoing separate formatting settings class * Moving TranslationSettings to base class * Moving CommentExpression to its own class * Basic support for parameterless lambda to source code translation * Adding class + method expression factory methods / Ensuring source code expressions can be visited * Support for translation of Action lambdas * support for parameterised lambda to class method translation * Extending test coverage * Organising tests * Support for converting non-lambdas to methods * Support for listing usings in source code translations * Recognising required usings from static member accesses * Including usings from Method parameters * Including usings from method return types * Passing unscoped, accessed variables into stand-alone method translations * Extra test coverage * Including usings from New expressions * Adding usings from generic type arguments * Adding usings for generic method type arguments / Sorting System usings first * Only including explicit generic arguments in required usings list * Support for custom class names * Extra test coverage / Fixing params parameter + non-params argument translation * Support for customising generated code namespace * Support for generating code in a given Type's namespace * Including extension method usings * Support for custom generated method names * Support for translating blocks with multiple lambdas into multi-class source code * Passing context classes to custom source code naming methods * Ensuring generated source code source compiles * Tidying * Support for naming methods using the ClassExpression and IMethodNamingContext * Support for source-code-level method naming * Adding usings from static method calls and catch block variables * Including usings from Enum member accesses * Extra test coverage * Support for multi-method classes * Updating documentation * Support for adding generated class summary documentation using CommentExpressions * Start of source code-building API * Adding custom class and method naming to source code building * Support for multi-class, multi-method SourceCodeExpression building * Erroring if duplicate method name specified * Erroring if duplicate class name specified * Support for adding summaries to methods * Start of inline block handling * Continued * Extracting inline Expressions to class methods and embedding method calls * Support for generating private helper methods from multi-line inline blocks * Moving class generation tests to source code generation * Migrating final class translation tests / Removing class translation extension method * Consolidating tests, removing public ClassExpression API * Migrating method expression + translation tests to full source code translation * Enabling passing of non-Lambda expressions to Method builder * New test * Handling parameters for inline block methods * Handling empty blocks, re: issue #78 / Merging refactoring from source code generation branch * v2.5.1 NuGet package and v3.3.1 Visualizers * Managing multi-line block method extraction * Splitting out source code analysis and translation/ Resetting source code variable scope calculation / Organising SourceCode classes * Fixing source code translation * Fixing using list generation * Start of MethodScope analysis * Handling unscoped variable accesses in top-level MethodExpressions * Start of multiline block -> method conversion * Handling passing parameters to extracted block methods * Validating custom class and method anmes * Validating built source code * Support for no-namespace classes * Erroring if a block has an invalid structure * Enforcing block expression structure * Support for building classes implementing interfaces * Support for building classes which implement multiple interfaces * Ensuring Class Interfaces are non-null * Test coverage for ambiguous interface implementatiion matches * Start of split to dedicated .Build project * Fixing project build * Moving tests to Build namespace * Updating Build to net46 + netstandard1.3, adding Build.Utilities package * Adding build.targets file and start of MsBuild Task * Splitting Build tests into dedicated projects * Filling in build task steps * Adding file abstraction * Adding .NET Standard compiler / Build task completed * Adding .NET Framework Build test console app * Adding compiler unit tests, NetFramework Compiler passes! * Working NetStandardCompiler! * Getting ExpressionBuilder class irrespective of namespace * Plugging NetStandardCompiler into build task * Updating ReadableExpressions to v3 / NetFramework console package install working! * Adding .NET Core Build test console app * Adding Build template files to contentFiles package path for .NET Core * Using MsBuild task to write ExpressionBuilder files during .NET Core compilation * Making members public and adding documentation to support BuildableExpressions as a separate package * Refactoring and making members publix * Making members public and adding documentation * Removing build projects * Removing .Build NuGet bat file * Updating package description * Making CommentExpression visitable * Converting CommentExpression to a type of ConstantExpression so it can be compiled * Reinstating a compilable ComentExpression! * Updating ExpressionAnalysis to support replacement of the analysed Expression's nodes * Allowing setting ExpressionAnalysis.ResultExpression from derived types * Adding LambdaExpression.Update extension method / Surfacing various ExpressionAnalysis methods for override * Handling updated assignments in ExpressionAnalysis * Moving interfaces out of dedicated namespace * Support for custom ITranslation use in ExpressionTranslation * Removing redundant ctor modifier * Revert "Removing redundant ctor modifier" This reverts commit a24a6c1. * Support for surfacing BCL Expressions from Extension Expressions for analysis * Updating visualizers to v3.4 * Adding ILMerge as a tool as NuGet package seems to silently fail * Splitting NetStandardPolyfills and ReadableExpressions out from visualizer object source assemblies to support custom translations * v3.4 Visualizer assemblies and installer * Support for merging ExpressionAnalysis * Including class and new() generic parameter constraints in Method translations * Handling generic parameter struct constraints * Start of interface type constraint translation * Support for translating generic parameters with interface type constraints / Switching IMethod to use ReadOnlyCollections * Support for translating generic argument class type constraints * Support for translating struct and multiple interface constraints * Extending constrain translation test coverage * Support for custom open IGenericArguments * Adding GenericArgumentTranslation * Surfacing TypeOfOperatorTranslation * Surfacing an operator translation base type * Surfacing a DefaultOperatorTranslation * Simplifying IGenericArgument * Support for specifying a custom Expression default value behaviour * Using BCL method to get generic argument type constraints * Only allowing default translation null keywords for closed generic types * Adding IMethod.IsOverride extension method, including override keyword in MethodInfo translation * Handling null method declaring types * Fixing method definition size estimation * Adding IsOverride as an IMethod member * Splitting out generic parameter and generic parameter constrain translation * Support for conversion of ICustomAnalysableExpressions * Adding IProperty for property abstraction translation / Surfacing more reflection translation infrastructure / Fixing overridden property translation * Fixing test * Support for Private Protected accessor translation * Support for overriding property accessor start and end translation * Usin property instead of accessor to determine scope * Skipping modifiers for interface Property translation * Ading marker interface for interface member translation * Tweaking interface member marker interface * Support for using a type abstraction for type translation * Extending support for translation of abstractions * Support for translating constant fields * Switching NuGet packer to msbuild to re-enable .NET 3.5 * Support for translation of a ctor abstraction * Surfacing ParameterSetTranslation * Adding .NET Standard 2.0 target / Updating NetStandardPoyfills reference / Updating to v2.6 * Updating years * Adding UnitTests.Common project * Updating NuGet packages * Adding test project for .NET Standard 1.0 target / Fixing escape character translation in verbatim strings * Fixign project whitespace * Removing 'Interfaces' namespace * Adding v2.6 NuGet package * Adding v2.6 preview NuGet package * Fixing project merge * Fixing sttaic method translation in helper factory method * Exposing Assembly from IType * Support for translating static constructors * Optimising default(v09d) and default 'null' translations * Fixing generic arguments supplied by null method arguments * Fixing 'upcast to object' translations * Fixing potential BclTypeWrapper dictionary threading issue * Renaming 'Bcl' types to 'Clr' * Removing explicit object casting from string -> object casts * Simplifying DefaultValueTranslation check * Updating for new Polyfills methods * Using updated method arguments in Expression analysis * Translating simple-type array constants to new array init expressions * Translating Regex constants into new Regex expressions * Handling array constants with non-array types * Showing object casts in nested cast Expressions / Removing unused code * Surfacing ExpressionAnalysis Lambda VisitAndConvert * Handling non-MethodCallExpression Call Expressions when analysing lambda arguments * Fixing nested casts check * Only converting lambdas to method groups if return types match * Providing an ExpressionAnalysis extension point for determining if a variable should be included in a block's variable declaration list * Removing switch case break statements when a case ends with a return or throw * Removing unreachable statements from block and switch case expressions * Simplifying package icon * Making block variable declaration determination more accurate * Extra test coverage * Adding Singleton ClrTypeWrapper for System.Attribute * Adding NuGet package path to main project * Support for translating flags enum constants * Fixing handling of base Enum type * Surfacing an empty ITranslatable object * Surfacing IPotentialEmptyTranslatable * Switching EmptyTranslatble.Instance to IPotentialEmptyTranslatable * Proviing extension point for start of property translations / Fixing documentation typo * Surfacing translation helper extensions * Tidying * Tidying * Fixing documentation typos * Optimising parameter set argument translation * Removing unnecessary null check * Tidying * Support for extension of method and constructor parameter definition translations * Ading IParameter.IsRef * Optimising indexer method call translation * Simplifying indexer method call check * Handling comment strings which already contain slashes * Improving variable name generation * Extra test coverage * Removing unused method * Updating readme and package tags * Updating logo image * Fixing Increment + Decrement translation, re: #84 * Updating release notes * Switching version back to preview1 * Start of readthedocs documentation * Updating dox index * Fixing readme links * Updating extension methods links * Documentating extension methods * Update extension-methods.md * Extensibililty documentation * Dox update * Dox * Adding v3-preview1 NuGet package
1 parent 53952b0 commit c2b13c0

File tree

204 files changed

+9379
-2217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+9379
-2217
lines changed

.gitignore

+199-200
Large diffs are not rendered by default.
Binary file not shown.

CommonVisualizerAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
[assembly: AssemblyCopyright("Copyright © 2020")]
88
[assembly: NeutralResourcesLanguage("en")]
99

10-
[assembly: AssemblyVersion("3.3.1")]
11-
[assembly: AssemblyFileVersion("3.3.1")]
10+
[assembly: AssemblyVersion("3.4.0")]
11+
[assembly: AssemblyFileVersion("3.4.0")]

Icon.pdn

-10.3 KB
Binary file not shown.

Icon.png

-2.29 KB
Loading

LICENSE.md renamed to LICENCE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 AgileObjects Ltd
3+
Copyright (c) 2021 AgileObjects Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
Binary file not shown.

NuGetPack.bat

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
@echo off
2-
dotnet pack --output NuGet --configuration Release ReadableExpressions
2+
dotnet restore
3+
msbuild ReadableExpressions /t:Pack /p:PackageOutputPath=../NuGet /p:Configuration=Release /v:m

README.md

+25-91
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
## ReadableExpressions
1+
# ReadableExpressions
22

3-
[![NuGet](http://img.shields.io/nuget/v/AgileObjects.ReadableExpressions.svg)](https://www.nuget.org/packages/AgileObjects.ReadableExpressions)
3+
ReadableExpressions provides extension methods and a
4+
[Debugger Visualizer](https://marketplace.visualstudio.com/items?itemName=vs-publisher-1232914.ReadableExpressionsVisualizers)
5+
for readable, source-code versions of
6+
[Expression Trees](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees),
7+
as well as reflection objects like `Type`, `FieldInfo`, `PropertyInfo`, etc.
48

5-
ReadableExpressions is set of [Debugger Visualizers](https://marketplace.visualstudio.com/items?itemName=vs-publisher-1232914.ReadableExpressionsVisualizers)
6-
and [a NuGet-packaged](https://www.nuget.org/packages/AgileObjects.ReadableExpressions) extension method for
7-
readable, source-code versions of [Expression Trees](https://msdn.microsoft.com/en-us/library/bb397951.aspx).
9+
## Debugger Visualizer
810

9-
### Debugger Visualizers
10-
11-
An installer for the Expression Debugger Visualizers can be downloaded from
11+
The Debugger Visualizer installer can be downloaded from
1212
[the Visual Studio Gallery](https://marketplace.visualstudio.com/items?itemName=vs-publisher-1232914.ReadableExpressionsVisualizers).
1313

1414
The visualizer has both Light and Dark themes:
1515

16-
[![Visualizer themes](/docs/Themes.gif)]
16+
[![Visualizer themes](/docs/src/assets/images/Themes.gif)]
1717

1818
...and output can be customised using various options:
1919

20-
[![Visualizer options](/docs/Options.gif)]
20+
[![Visualizer options](/docs/src/assets/images/Options.gif)]
2121

2222
## ASP.NET Core 5 Known Issue
2323

24-
.NET 5 has [a breaking change](https://github.com/dotnet/runtime/issues/29976), which disables `BinaryFormatter` serialization by default. This causes issues with the ReadableExpressions visualizers (and [elsewhere](https://github.com/nhibernate/nhibernate-core/issues/2603)) when debugging ASP.NET Core apps as the VS debugger [uses](https://wrightfully.com/writing-a-readonly-debugger-visualizer) `BinaryFormatter` to serialize objects before sending them to the visualizer.
24+
.NET 5 had [a breaking change](https://github.com/dotnet/runtime/issues/29976), which disables `BinaryFormatter` serialization by default.
25+
This has caused issues with the ReadableExpressions visualizers (and [elsewhere](https://github.com/nhibernate/nhibernate-core/issues/2603))
26+
when debugging ASP.NET Core apps as the VS debugger [uses](https://wrightfully.com/writing-a-readonly-debugger-visualizer) `BinaryFormatter`
27+
to serialize objects before sending them to the visualizer.
2528

26-
[The solution](https://developercommunity2.visualstudio.com/t/visual-studio-debugger-visualizers-and-binaryforma/1278642?from=email&viewtype=all#T-N1314383) is to enable the `BinaryFormatter` in Debug only by adding the following to your ASP.NET Core csproj:
29+
[The solution](https://developercommunity2.visualstudio.com/t/visual-studio-debugger-visualizers-and-binaryforma/1278642) is to enable the
30+
`BinaryFormatter` in Debug only by adding the following to your ASP.NET Core csproj:
2731

2832
```xml
2933
<PropertyGroup>
@@ -34,96 +38,26 @@ The visualizer has both Light and Dark themes:
3438
</PropertyGroup>
3539
```
3640

37-
### NuGet Package
41+
## Extension Methods
3842

39-
The extension method is available in [a NuGet package](https://www.nuget.org/packages/AgileObjects.ReadableExpressions)
40-
targeting [.NETStandard 1.0](https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard)+ and
41-
.NET 3.5+:
43+
[The extension methods](https://readableexpressions.readthedocs.io/extension-methods) are available
44+
[on NuGet](https://www.nuget.org/packages/AgileObjects.ReadableExpressions),
45+
and target .NET 3.5+ and [.NETStandard 1.0](https://dotnet.microsoft.com/platform/dotnet-standard)+:
4246

4347
```shell
4448
PM> Install-Package AgileObjects.ReadableExpressions
4549
```
50+
[![NuGet version](https://badge.fury.io/nu/AgileObjects.ReadableExpressions.svg)](https://badge.fury.io/nu/AgileObjects.ReadableExpressions)
4651

47-
...and is used like so:
52+
To translate an Expression, use:
4853

4954
```csharp
5055
using AgileObjects.ReadableExpressions;
5156

5257
string readable = myExpression.ToReadableString();
5358
```
5459

55-
...it also works on [DynamicLanguageRuntime](https://www.nuget.org/packages/DynamicLanguageRuntime) expressions.
56-
57-
### Options
58-
59-
To include namespaces when outputting type names, use:
60-
61-
```csharp
62-
string readable = myExpression
63-
.ToReadableString(c => c.UseFullyQualifiedTypeNames);
64-
```
65-
66-
To use full type names instead of `var` for local and inline-declared output parameter variables, use:
67-
68-
```csharp
69-
string readable = myExpression
70-
.ToReadableString(c => c.UseExplicitTypeNames);
71-
```
72-
73-
To declare output parameter variables inline with the method where they are first used, use:
60+
...this also works on [DynamicLanguageRuntime](https://www.nuget.org/packages/DynamicLanguageRuntime) expressions.
7461

75-
```csharp
76-
string readable = myExpression
77-
.ToReadableString(c => c.DeclareOutputParametersInline);
78-
```
79-
80-
To maintain explicit generic arguments on method calls where they are implied, use:
81-
82-
```csharp
83-
string readable = myExpression
84-
.ToReadableString(c => c.UseExplicitGenericParameters);
85-
```
86-
87-
To show implicitly-typed array type names, use:
88-
89-
```csharp
90-
string readable = myExpression
91-
.ToReadableString(c => c.ShowImplicitArrayTypes);
92-
```
93-
94-
To show lambda parameter type names, use:
95-
96-
```csharp
97-
string readable = myExpression
98-
.ToReadableString(c => c.ShowLambdaParameterTypes);
99-
```
100-
101-
To output a source code comment when a lambda is '[quoted](https://stackoverflow.com/questions/3716492/what-does-expression-quote-do-that-expression-constant-can-t-already-do)', use:
102-
103-
```csharp
104-
string readable = myExpression
105-
.ToReadableString(c => c.ShowQuotedLambdaComments);
106-
```
107-
108-
To define a custom factory for naming anonymous types, use:
109-
110-
```csharp
111-
string readable = myExpression
112-
.ToReadableString(c => c.NameAnonymousTypesUsing(
113-
anonType => GetAnonTypeName(anonType)));
114-
```
115-
116-
To define a custom factory for translating `ConstantExpression` values, use:
117-
118-
```csharp
119-
string readable = myExpression
120-
.ToReadableString(c => c.TranslateConstantsUsing(
121-
(constantType, constantValue) => GetConstantValue(constantType, constantValue)));
122-
```
123-
124-
To specify a custom string for code indenting, use:
125-
126-
```csharp
127-
string readable = myExpression
128-
.ToReadableString(c => c.IndentUsing("\t"));
129-
```
62+
All code is licensed with the [MIT licence](LICENCE.md). Check out
63+
[the documentation](https://readableexpressions.readthedocs.io) for more!

ReadableExpressions.UnitTests.Common/OddNumber.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AgileObjects.ReadableExpressions.UnitTests.Common
1+
namespace AgileObjects.ReadableExpressions.UnitTests.Common
22
{
33
public enum OddNumber
44
{

ReadableExpressions.UnitTests.Common/ReadableExpressions.UnitTests.Common.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net35;net461;netstandard1.3</TargetFrameworks>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
3+
namespace AgileObjects.ReadableExpressions.UnitTests.Common
4+
{
5+
public static class Should
6+
{
7+
public static TException Throw<TException>(Action test)
8+
where TException : Exception
9+
{
10+
return Throw<TException>(() =>
11+
{
12+
test.Invoke();
13+
14+
return new object();
15+
});
16+
}
17+
18+
public static TException Throw<TException>(Func<object> testFunc)
19+
where TException : Exception
20+
{
21+
try
22+
{
23+
testFunc.Invoke();
24+
}
25+
catch (TException ex)
26+
{
27+
return ex;
28+
}
29+
30+
throw new Exception("Expected exception of type " + typeof(TException).Name);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace AgileObjects.ReadableExpressions.UnitTests.Common
2+
{
3+
#if NET35
4+
using Microsoft.Scripting.Ast;
5+
#else
6+
using System.Linq.Expressions;
7+
#endif
8+
using Translations;
9+
10+
public class TestTranslationContext : ExpressionTranslation
11+
{
12+
public TestTranslationContext(Expression expression)
13+
: base(expression, TestTranslationSettings.TestSettings)
14+
{
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AgileObjects.ReadableExpressions.UnitTests.Common
2+
{
3+
public class TestTranslationSettings : TranslationSettings
4+
{
5+
public static readonly TranslationSettings TestSettings = new TestTranslationSettings();
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace AgileObjects.ReadableExpressions.UnitTests.Common
2+
{
3+
using Translations;
4+
5+
public class TestTranslationWriter : TranslationWriter
6+
{
7+
public TestTranslationWriter(ITranslatable translatable)
8+
: base(TestTranslationSettings.TestSettings, translatable)
9+
{
10+
}
11+
}
12+
}

ReadableExpressions.UnitTests.Net35/ReadableExpressions.UnitTests.Net35.csproj

+2-14
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,17 @@
2121
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
2222
</PropertyGroup>
2323

24-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
25-
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
26-
</PropertyGroup>
27-
28-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
29-
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
30-
</PropertyGroup>
31-
3224
<ItemGroup>
3325
<Compile Include="..\ReadableExpressions.UnitTests\**\*.cs" Exclude="..\ReadableExpressions.UnitTests\obj\**\*.cs;">
3426
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
3527
</Compile>
3628
</ItemGroup>
3729

38-
<ItemGroup>
39-
<Compile Remove="..\ReadableExpressions.UnitTests\ShouldExtensions.cs" />
40-
</ItemGroup>
41-
4230
<ItemGroup>
4331
<Reference Include="System" />
4432
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
45-
<PackageReference Include="NUnit" Version="3.13.1" />
46-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
33+
<PackageReference Include="NUnit" Version="3.12.0" />
34+
<PackageReference Include="NUnit3TestAdapter" Version="3.7.0">
4735
<PrivateAssets>all</PrivateAssets>
4836
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4937
</PackageReference>

0 commit comments

Comments
 (0)