Skip to content

Commit a561822

Browse files
author
Alex Davies
committed
Migrate to VS2017. Include build for netstandard1.0, bump version to 1.0.0.
1 parent e25e6ba commit a561822

17 files changed

+86
-325
lines changed

.nuget/nuget.exe

-4.07 MB
Binary file not shown.

StringToExpression.sln

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26228.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DAB89BA5-F320-49BD-A68E-12E3C7191CDD}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringToExpression", "src\StringToExpression\StringToExpression.csproj", "{B1B0A26F-04E2-40E5-B25C-12764E50BEFC}"
9-
EndProject
108
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{03FEEEAD-4F6F-4573-83E4-E4CABAA242A8}"
119
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringToExpression.Test", "tests\StringToExpression.Test\StringToExpression.Test.csproj", "{D3E70B64-E690-40BC-800F-5C463386E951}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StringToExpression", "src\StringToExpression\StringToExpression.csproj", "{718F11D6-BD9A-4267-95D0-10446D7E0877}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringToExpression.Test", "tests\StringToExpression.Test\StringToExpression.Test.csproj", "{D2058E9F-F528-46CF-89CA-762473CECBB1}"
1313
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1616
Debug|Any CPU = Debug|Any CPU
1717
Release|Any CPU = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20-
{B1B0A26F-04E2-40E5-B25C-12764E50BEFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{B1B0A26F-04E2-40E5-B25C-12764E50BEFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{B1B0A26F-04E2-40E5-B25C-12764E50BEFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{B1B0A26F-04E2-40E5-B25C-12764E50BEFC}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{D3E70B64-E690-40BC-800F-5C463386E951}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{D3E70B64-E690-40BC-800F-5C463386E951}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{D3E70B64-E690-40BC-800F-5C463386E951}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{D3E70B64-E690-40BC-800F-5C463386E951}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{718F11D6-BD9A-4267-95D0-10446D7E0877}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{718F11D6-BD9A-4267-95D0-10446D7E0877}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{718F11D6-BD9A-4267-95D0-10446D7E0877}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{718F11D6-BD9A-4267-95D0-10446D7E0877}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{D2058E9F-F528-46CF-89CA-762473CECBB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{D2058E9F-F528-46CF-89CA-762473CECBB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{D2058E9F-F528-46CF-89CA-762473CECBB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{D2058E9F-F528-46CF-89CA-762473CECBB1}.Release|Any CPU.Build.0 = Release|Any CPU
2828
EndGlobalSection
2929
GlobalSection(SolutionProperties) = preSolution
3030
HideSolutionNode = FALSE
3131
EndGlobalSection
3232
GlobalSection(NestedProjects) = preSolution
33-
{B1B0A26F-04E2-40E5-B25C-12764E50BEFC} = {DAB89BA5-F320-49BD-A68E-12E3C7191CDD}
34-
{D3E70B64-E690-40BC-800F-5C463386E951} = {03FEEEAD-4F6F-4573-83E4-E4CABAA242A8}
33+
{718F11D6-BD9A-4267-95D0-10446D7E0877} = {DAB89BA5-F320-49BD-A68E-12E3C7191CDD}
34+
{D2058E9F-F528-46CF-89CA-762473CECBB1} = {03FEEEAD-4F6F-4573-83E4-E4CABAA242A8}
3535
EndGlobalSection
3636
EndGlobal

build/build.bat

-1
This file was deleted.

build/package.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dotnet build ..\src\StringToExpression\StringToExpression.csproj --configuration=Release
2+
dotnet pack ..\src\StringToExpression\StringToExpression.csproj --configuration=Release --output ../../artifacts

src/StringToExpression/GrammerDefinitions/BracketCloseDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public BracketCloseDefinition(string name, string regex,
4242
{
4343
if (bracketOpenDefinitions == null)
4444
throw new ArgumentNullException(nameof(bracketOpenDefinitions));
45-
this.BracketOpenDefinitions = bracketOpenDefinitions.ToList().AsReadOnly();
45+
this.BracketOpenDefinitions = bracketOpenDefinitions.ToList();
4646
this.ListDelimeterDefinition = listDelimeterDefinition;
4747
}
4848

src/StringToExpression/GrammerDefinitions/FunctionCallDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public FunctionCallDefinition(
4141
Func<Expression[], Expression> expressionBuilder)
4242
: base(name, regex)
4343
{
44-
this.ArgumentTypes = argumentTypes?.ToList()?.AsReadOnly();
44+
this.ArgumentTypes = argumentTypes?.ToList();
4545
this.ExpressionBuilder = expressionBuilder;
4646
}
4747

src/StringToExpression/GrammerDefinitions/OperatorDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public OperatorDefinition(string name,
9494
if (expressionBuilder == null)
9595
throw new ArgumentNullException(nameof(expressionBuilder));
9696

97-
ParamaterPositions = paramaterPositions.ToList().AsReadOnly();
97+
ParamaterPositions = paramaterPositions.ToList();
9898
ExpressionBuilder = expressionBuilder;
9999
OrderOfPrecedence = orderOfPrecedence;
100100
}

src/StringToExpression/Languages/ArithmeticLanguage.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,7 @@ protected virtual IEnumerable<GrammerDefinition> PropertyDefinitions()
224224
expressionBuilder: (value, parameters) => {
225225
return value.Split('.').Aggregate((Expression)parameters[0], (exp, prop)=>
226226
{
227-
return Expression.MakeMemberAccess(exp, exp.Type.GetProperty(prop,
228-
BindingFlags.Instance
229-
| BindingFlags.Public
230-
| BindingFlags.GetProperty
231-
| BindingFlags.IgnoreCase));
227+
return Expression.MakeMemberAccess(exp, TypeShim.GetProperty(exp.Type, prop));
232228
});
233229
}),
234230
};

src/StringToExpression/Languages/ODataFilterLanguage.cs

+14-18
Original file line numberDiff line numberDiff line change
@@ -144,45 +144,45 @@ protected virtual IEnumerable<GrammerDefinition> LogicalOperatorDefinitions()
144144
name:"EQ",
145145
regex: @"eq",
146146
orderOfPrecedence:11,
147-
expressionBuilder: Expression.Equal),
147+
expressionBuilder: (left,right) => Expression.Equal(left, right)),
148148
new BinaryOperatorDefinition(
149149
name:"NE",
150150
regex: @"ne",
151151
orderOfPrecedence:12,
152-
expressionBuilder: Expression.NotEqual),
152+
expressionBuilder: (left,right) => Expression.NotEqual(left, right)),
153153

154154
new BinaryOperatorDefinition(
155155
name:"GT",
156156
regex: @"gt",
157157
orderOfPrecedence:13,
158-
expressionBuilder: Expression.GreaterThan),
158+
expressionBuilder: (left,right) => Expression.GreaterThan(left, right)),
159159
new BinaryOperatorDefinition(
160160
name:"GE",
161161
regex: @"ge",
162162
orderOfPrecedence:14,
163-
expressionBuilder: Expression.GreaterThanOrEqual),
163+
expressionBuilder: (left,right) => Expression.GreaterThanOrEqual(left, right)),
164164

165165
new BinaryOperatorDefinition(
166166
name:"LT",
167167
regex: @"lt",
168168
orderOfPrecedence:15,
169-
expressionBuilder: Expression.LessThan),
169+
expressionBuilder: (left,right) => Expression.LessThan(left, right)),
170170
new BinaryOperatorDefinition(
171171
name:"LE",
172172
regex: @"le",
173173
orderOfPrecedence:16,
174-
expressionBuilder: Expression.LessThanOrEqual),
174+
expressionBuilder: (left,right) => Expression.LessThanOrEqual(left, right)),
175175

176176
new BinaryOperatorDefinition(
177177
name:"AND",
178178
regex: @"and",
179179
orderOfPrecedence:17,
180-
expressionBuilder: Expression.AndAlso),
180+
expressionBuilder: (left,right) => Expression.And(left, right)),
181181
new BinaryOperatorDefinition(
182182
name:"OR",
183183
regex: @"or",
184184
orderOfPrecedence:18,
185-
expressionBuilder: Expression.OrElse),
185+
expressionBuilder: (left,right) => Expression.Or(left, right)),
186186

187187
new UnaryOperatorDefinition(
188188
name:"NOT",
@@ -208,27 +208,27 @@ protected virtual IEnumerable<GrammerDefinition> ArithmeticOperatorDefinitions()
208208
name:"ADD",
209209
regex: @"add",
210210
orderOfPrecedence: 2,
211-
expressionBuilder: Expression.Add),
211+
expressionBuilder: (left,right) => Expression.Add(left, right)),
212212
new BinaryOperatorDefinition(
213213
name:"SUB",
214214
regex: @"sub",
215215
orderOfPrecedence: 2,
216-
expressionBuilder: Expression.Subtract),
216+
expressionBuilder: (left,right) => Expression.Subtract(left, right)),
217217
new BinaryOperatorDefinition(
218218
name:"MUL",
219219
regex: @"mul",
220220
orderOfPrecedence: 1,
221-
expressionBuilder: Expression.Multiply),
221+
expressionBuilder: (left,right) => Expression.Multiply(left, right)),
222222
new BinaryOperatorDefinition(
223223
name:"DIV",
224224
regex: @"div",
225225
orderOfPrecedence: 1,
226-
expressionBuilder: Expression.Divide),
226+
expressionBuilder: (left,right) => Expression.Divide(left, right)),
227227
new BinaryOperatorDefinition(
228228
name:"MOD",
229229
regex: @"mod",
230230
orderOfPrecedence: 1,
231-
expressionBuilder: Expression.Modulo),
231+
expressionBuilder: (left,right) => Expression.Modulo(left, right)),
232232
};
233233
}
234234

@@ -383,11 +383,7 @@ protected virtual IEnumerable<GrammerDefinition> PropertyDefinitions()
383383
name:"PROPERTY_PATH",
384384
regex: @"(?<![0-9])([A-Za-z_][A-Za-z0-9_]*/?)+",
385385
expressionBuilder: (value, parameters) => {
386-
return value.Split('/').Aggregate((Expression)parameters[0], (exp, prop)=> Expression.MakeMemberAccess(exp, exp.Type.GetProperty(prop,
387-
BindingFlags.Instance
388-
| BindingFlags.Public
389-
| BindingFlags.GetProperty
390-
| BindingFlags.IgnoreCase)));
386+
return value.Split('/').Aggregate((Expression)parameters[0], (exp, prop)=> Expression.MakeMemberAccess(exp, TypeShim.GetProperty(exp.Type, prop)));
391387
}),
392388
};
393389
}

src/StringToExpression/Properties/AssemblyInfo.cs

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,17 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{B1B0A26F-04E2-40E5-B25C-12764E50BEFC}</ProjectGuid>
8-
<OutputType>Library</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>StringToExpression</RootNamespace>
11-
<AssemblyName>StringToExpression</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
4+
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
5+
<Company>Codecutout</Company>
6+
<Authors>Alex Davies</Authors>
7+
<Description>StringToExpression supports the compiling a domain specific string into a .NET expression.
8+
9+
Out of the box configuration is provided for parsing arithmetic expressions and for parsing OData filter strings. Although can be configured to parse string of any format</Description>
10+
<Copyright>Copyright © 2017</Copyright>
11+
<PackageLicenseUrl>https://github.com/codecutout/StringToExpression/blob/master/LICENSE</PackageLicenseUrl>
12+
<PackageProjectUrl>https://github.com/codecutout/StringToExpression</PackageProjectUrl>
13+
<PackageTags>Expression Filter OData Arithmetic DSL</PackageTags>
14+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1415
</PropertyGroup>
15-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16-
<DebugSymbols>true</DebugSymbols>
17-
<DebugType>full</DebugType>
18-
<Optimize>false</Optimize>
19-
<OutputPath>bin\</OutputPath>
20-
<DefineConstants>DEBUG;TRACE</DefineConstants>
21-
<ErrorReport>prompt</ErrorReport>
22-
<WarningLevel>4</WarningLevel>
23-
<DocumentationFile>bin\StringToExpression.XML</DocumentationFile>
24-
<NoWarn>
25-
</NoWarn>
26-
</PropertyGroup>
27-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28-
<DebugType>pdbonly</DebugType>
29-
<Optimize>true</Optimize>
30-
<OutputPath>bin\</OutputPath>
31-
<DefineConstants>TRACE</DefineConstants>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
<DocumentationFile>bin\StringToExpression.XML</DocumentationFile>
35-
<NoWarn>1591</NoWarn>
36-
</PropertyGroup>
37-
<ItemGroup>
38-
<Reference Include="System" />
39-
<Reference Include="System.Core" />
40-
<Reference Include="System.Xml.Linq" />
41-
<Reference Include="System.Data.DataSetExtensions" />
42-
<Reference Include="Microsoft.CSharp" />
43-
<Reference Include="System.Data" />
44-
<Reference Include="System.Net.Http" />
45-
<Reference Include="System.Xml" />
46-
</ItemGroup>
47-
<ItemGroup>
48-
<Compile Include="Exceptions\BracketUnmatchedException.cs" />
49-
<Compile Include="Exceptions\FunctionArgumentCountException.cs" />
50-
<Compile Include="Exceptions\ListDelimeterNotWithinBrackets.cs" />
51-
<Compile Include="Exceptions\FunctionArgumentTypeException.cs" />
52-
<Compile Include="Exceptions\GrammerDefinitionDuplicateNameException.cs" />
53-
<Compile Include="Exceptions\GrammerDefinitionInvalidNameException.cs" />
54-
<Compile Include="Exceptions\OperandExpectedException.cs" />
55-
<Compile Include="Exceptions\OperandUnexpectedException.cs" />
56-
<Compile Include="Exceptions\OperationInvalidException.cs" />
57-
<Compile Include="Exceptions\ParseException.cs" />
58-
<Compile Include="Languages\ArithmeticLanguage.cs" />
59-
<Compile Include="Languages\ODataFilterLanguage.cs" />
60-
<Compile Include="Parser\Operand.cs" />
61-
<Compile Include="Parser\Operator.cs" />
62-
<Compile Include="Parser\Parser.cs" />
63-
<Compile Include="Parser\ParseState.cs" />
64-
<Compile Include="GrammerDefinitions\FunctionCallDefinition.cs" />
65-
<Compile Include="GrammerDefinitions\ListDelimiterDefinition.cs" />
66-
<Compile Include="GrammerDefinitions\UnaryOperatorDefinition.cs" />
67-
<Compile Include="GrammerDefinitions\BracketCloseDefinition.cs" />
68-
<Compile Include="GrammerDefinitions\BracketOpenDefinition.cs" />
69-
<Compile Include="GrammerDefinitions\BinaryOperatorDefinition.cs" />
70-
<Compile Include="GrammerDefinitions\OperatorDefinition.cs" />
71-
<Compile Include="GrammerDefinitions\OperandDefinition.cs" />
72-
<Compile Include="GrammerDefinitions\GrammerDefinition.cs" />
73-
<Compile Include="Exceptions\GrammerUnexpectedException.cs" />
74-
<Compile Include="Language.cs" />
75-
<Compile Include="Properties\AssemblyInfo.cs" />
76-
<Compile Include="Tokenizer\Token.cs" />
77-
<Compile Include="Tokenizer\Tokenizer.cs" />
78-
<Compile Include="Util\ExpressionConversions.cs" />
79-
<Compile Include="Util\StackExtensions.cs" />
80-
<Compile Include="Util\StringSegment.cs" />
81-
<Compile Include="Util\Type.cs" />
82-
</ItemGroup>
83-
<ItemGroup>
84-
<None Include="StringToExpression.nuspec" />
85-
</ItemGroup>
86-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
87-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
88-
Other similar extension points exist, see Microsoft.Common.targets.
89-
<Target Name="BeforeBuild">
90-
</Target>
91-
<Target Name="AfterBuild">
92-
</Target>
93-
-->
16+
9417
</Project>

src/StringToExpression/StringToExpression.nuspec

-16
This file was deleted.

src/StringToExpression/Tokenizer/Tokenizer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public Tokenizer(params GrammerDefinition[] grammerDefinitions)
3434
var duplicateKey = grammerDefinitions.GroupBy(x => x.Name).FirstOrDefault(g => g.Count() > 1)?.Key;
3535
if (duplicateKey != null)
3636
throw new GrammerDefinitionDuplicateNameException(duplicateKey);
37-
38-
GrammerDefinitions = grammerDefinitions.ToList().AsReadOnly();
37+
38+
GrammerDefinitions = grammerDefinitions.ToList();
3939

4040
var pattern = string.Join("|", GrammerDefinitions.Select(x => $"(?<{x.Name}>{x.Regex})"));
4141
this.TokenRegex = new Regex(pattern);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
7+
namespace StringToExpression.Util
8+
{
9+
internal static class TypeShim
10+
{
11+
public static PropertyInfo GetProperty(Type type, string property)
12+
{
13+
#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4
14+
return type.GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals(property, StringComparison.OrdinalIgnoreCase));
15+
#else
16+
return type.GetTypeInfo().GetProperty(property, BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Public);
17+
#endif
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)