├── .gitignore ├── ExpressionBuilder ├── .nuget │ ├── NuGet.Config │ ├── NuGet.exe │ └── NuGet.targets ├── ExpressionBuilder.Test │ ├── AssertString.cs │ ├── CallingGenericFunctionsInside.cs │ ├── CodeLineTest.cs │ ├── ExpressionBuilder.Test.csproj │ ├── ExpressionUtilTest.cs │ ├── FunctionTest.cs │ ├── IfTest.cs │ ├── OperationTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── StringOperationTest.cs │ ├── ToDoTest.cs │ ├── WhileTest.cs │ └── packages.config ├── ExpressionBuilder.sln ├── ExpressionBuilder │ ├── CodeLine.cs │ ├── CodeLines │ │ ├── Assign.cs │ │ ├── CreateReturn.cs │ │ ├── CreateVariable.cs │ │ ├── Nop.cs │ │ ├── OperationAction.cs │ │ └── OperationInvoke.cs │ ├── CollectionOperation.cs │ ├── Condition.cs │ ├── Conditions │ │ ├── BinaryCondition.cs │ │ └── MultiCondition.cs │ ├── Enums │ │ ├── AssignementOperators.cs │ │ └── ComparaisonOperator.cs │ ├── ExpressionBuilder.csproj │ ├── ExpressionBuilder.nuspec │ ├── Fluent │ │ ├── IBodyOrParameter.cs │ │ ├── ICodeLine.cs │ │ ├── IElseIf.cs │ │ ├── IExpressionResult.cs │ │ ├── IFunctionBody.cs │ │ ├── IFunctionParameter.cs │ │ ├── IFunctionReturn.cs │ │ ├── IIf.cs │ │ ├── IIfThen.cs │ │ ├── ILeftRightable.cs │ │ ├── ILeftable.cs │ │ ├── IOperation.cs │ │ ├── IRightable.cs │ │ └── IWhile.cs │ ├── Function.cs │ ├── If.cs │ ├── Operation.cs │ ├── Operations │ │ ├── OperationCast.cs │ │ ├── OperationConst.cs │ │ ├── OperationFunc.cs │ │ ├── OperationInvokeReturn.cs │ │ ├── OperationNew.cs │ │ ├── OperationNewArrayInit.cs │ │ └── OperationVariable.cs │ ├── Parser │ │ ├── IParsable.cs │ │ ├── ParseContext.cs │ │ └── ParseLevel.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── StringOperation.cs │ ├── TODO.txt │ ├── Utils │ │ ├── ExpressionUtil.cs │ │ ├── LambdaPropertyDescriptor.cs │ │ ├── MethodCallDescriptor.cs │ │ ├── PropertyGetSet.cs │ │ └── ReflectionUtil.cs │ ├── Variable.cs │ └── While.cs └── build_utils │ ├── BuildCleaner.exe │ ├── CommentsHeader.exe │ ├── GenericHelpers.dll │ ├── Ionic.Zip.Reduced.dll │ ├── README.md │ ├── VisualStudioIdentifier.exe │ ├── dobuild.bat │ ├── dobuild_clean.bat │ ├── dobuild_env.bat │ ├── dobuild_env.template │ ├── dobuild_nuget.bat │ ├── dobuild_simple.bat │ ├── dobuild_single.bat │ ├── license.cs │ ├── setcopyright.bat │ ├── zipproject.bat │ └── ziproject.nuget.bat ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | .opencover_bin 16 | .report 17 | 18 | # Build results 19 | tmp_nuget/ 20 | [Dd]ebug/ 21 | [Rr]elease/ 22 | *_i.c 23 | *_p.c 24 | *.ilk 25 | *.meta 26 | *.obj 27 | *.pch 28 | *.pdb 29 | *.pgc 30 | *.pgd 31 | *.rsp 32 | *.sbr 33 | *.tlb 34 | *.tli 35 | *.tlh 36 | *.tmp 37 | *.log 38 | *.vspscc 39 | *.vssscc 40 | .builds 41 | 42 | # Visual C++ cache files 43 | ipch/ 44 | *.aps 45 | *.ncb 46 | *.opensdf 47 | *.sdf 48 | 49 | # Visual Studio profiler 50 | *.psess 51 | *.vsp 52 | *.vspx 53 | 54 | # Guidance Automation Toolkit 55 | *.gpState 56 | 57 | # ReSharper is a .NET coding add-in 58 | _ReSharper* 59 | 60 | # NCrunch 61 | *.ncrunch* 62 | .*crunch*.local.xml 63 | 64 | # Installshield output folder 65 | [Ee]xpress 66 | 67 | # DocProject is a documentation generator add-in 68 | DocProject/buildhelp/ 69 | DocProject/Help/*.HxT 70 | DocProject/Help/*.HxC 71 | DocProject/Help/*.hhc 72 | DocProject/Help/*.hhk 73 | DocProject/Help/*.hhp 74 | DocProject/Help/Html2 75 | DocProject/Help/html 76 | 77 | # Click-Once directory 78 | publish 79 | 80 | # Publish Web Output 81 | *.Publish.xml 82 | 83 | # NuGet Packages Directory 84 | packages/ 85 | tmp_nuget/ 86 | vs.bat 87 | 88 | # Windows Azure Build Output 89 | csx 90 | *.build.csdef 91 | 92 | # Windows Store app package directory 93 | AppPackages/ 94 | .nodeCs 95 | 96 | # Others 97 | [Bb]in 98 | [Oo]bj 99 | sql 100 | TestResults 101 | [Tt]est[Rr]esult* 102 | *.Cache 103 | ClientBin 104 | [Ss]tyle[Cc]op.* 105 | ~$* 106 | *.dbmdl 107 | Generated_Code #added for RIA/Silverlight projects 108 | 109 | # Backup & report files from converting an old project file to a newer 110 | # Visual Studio version. Backup files are not needed, because we have git ;-) 111 | _UpgradeReport_Files/ 112 | Backup*/ 113 | UpgradeLog*.XML 114 | 115 | App_Bin/ 116 | PerfMon/ 117 | -------------------------------------------------------------------------------- /ExpressionBuilder/.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ExpressionBuilder/.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/.nuget/NuGet.exe -------------------------------------------------------------------------------- /ExpressionBuilder/.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | 32 | 33 | 34 | 35 | $(SolutionDir).nuget 36 | 37 | 38 | 39 | packages.$(MSBuildProjectName.Replace(' ', '_')).config 40 | 41 | 42 | 43 | 44 | 45 | $(PackagesProjectConfig) 46 | 47 | 48 | 49 | 50 | packages.config 51 | 52 | 53 | 54 | 55 | 56 | 57 | $(NuGetToolsPath)\NuGet.exe 58 | @(PackageSource) 59 | 60 | "$(NuGetExePath)" 61 | mono --runtime=v4.0.30319 $(NuGetExePath) 62 | 63 | $(TargetDir.Trim('\\')) 64 | 65 | -RequireConsent 66 | -NonInteractive 67 | 68 | "$(SolutionDir) " 69 | "$(SolutionDir)" 70 | 71 | 72 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) 73 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols 74 | 75 | 76 | 77 | RestorePackages; 78 | $(BuildDependsOn); 79 | 80 | 81 | 82 | 83 | $(BuildDependsOn); 84 | BuildPackage; 85 | 86 | 87 | 88 | 89 | 90 | 91 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | 113 | 115 | 116 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/AssertString.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.ComponentModel; 30 | using System.Text; 31 | using Microsoft.VisualStudio.TestTools.UnitTesting; 32 | 33 | namespace ExpressionBuilder.Test 34 | { 35 | public static class AssertString 36 | { 37 | public static void AreEqual(string expected, string actual) 38 | { 39 | expected = expected.Replace("\r\n", "\n"); 40 | actual = actual.Replace("\r\n", "\n"); 41 | if (expected.Length == actual.Length) 42 | { 43 | for (var i = 0; i < expected.Length; i++) 44 | { 45 | var expectedChar = (int) expected[i]; 46 | var actualChar = (int)actual[i]; 47 | if (actualChar != expectedChar) 48 | { 49 | break; 50 | } 51 | } 52 | return; 53 | } 54 | throw new AssertFailedException(string.Format("AssertString.AreEqual\nExpected <{0}>\nActual <{1}>", expected, 55 | actual)); 56 | } 57 | 58 | public static string UTF8ToAscii(string text) 59 | { 60 | var utf8 = Encoding.UTF8; 61 | Byte[] encodedBytes = utf8.GetBytes(text); 62 | Byte[] convertedBytes = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, encodedBytes); 63 | 64 | return Encoding.ASCII.GetString(convertedBytes); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/CallingGenericFunctionsInside.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using System.Text; 32 | using Microsoft.VisualStudio.TestTools.UnitTesting; 33 | 34 | namespace ExpressionBuilder.Test 35 | { 36 | 37 | [TestClass] 38 | public class CallingGenericFunctionsInside 39 | { 40 | 41 | [TestMethod] 42 | public void ShouldBePossibleToCallLambdaFunction() 43 | { 44 | const string expected = 45 | @"public System.String Call(System.String first, System.String second) 46 | { 47 | System.String result; 48 | result = System.Func(first, second); 49 | return result; 50 | }"; 51 | 52 | var newExpression = Function.Create() 53 | .WithParameter("first") 54 | .WithParameter("second") 55 | .WithBody( 56 | CodeLine.CreateVariable("result"), 57 | CodeLine.Assign("result", 58 | Operation.Func( 59 | (a, b) => 60 | { 61 | b += "-extra"; 62 | return string.Format("{0}-{1}", a, b); 63 | }, 64 | Operation.Variable("first"), 65 | Operation.Variable("second")) 66 | ) 67 | ) 68 | .Returns("result"); 69 | 70 | 71 | AssertString.AreEqual(expected, newExpression.ToString()); 72 | 73 | var lambda = newExpression.ToLambda>(); 74 | Assert.IsNotNull(lambda); 75 | 76 | var result = lambda("a", "b"); 77 | Assert.AreEqual("a-b-extra", result); 78 | } 79 | 80 | [TestMethod] 81 | public void DoTest() 82 | { 83 | var lambda = new Action((path, type) => 84 | { 85 | 86 | return null; 87 | }); 88 | 89 | } 90 | 91 | public object DoInvocation(string path, Type type) 92 | { 93 | 94 | } 95 | 96 | public T GetAll(string path) where T : new() 97 | { 98 | return new T(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/ExpressionBuilder.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {499EAC63-E44E-48B6-85C4-5F6E5D2185E3} 7 | Library 8 | Properties 9 | ExpressionBuilder.Test 10 | ExpressionBuilder.Test 11 | v4.0 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | ..\..\..\ 21 | true 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | ..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | {f333183c-4688-4fa2-8346-dd62cbcf2896} 76 | ExpressionBuilder 77 | 78 | 79 | 80 | 81 | 82 | 83 | False 84 | 85 | 86 | False 87 | 88 | 89 | False 90 | 91 | 92 | False 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 103 | 104 | 105 | 106 | 113 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/ExpressionUtilTest.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System.Linq; 29 | //using ExpressionBuilder.Utils; 30 | using Microsoft.VisualStudio.TestTools.UnitTesting; 31 | using ExpressionBuilder.Utils; 32 | 33 | namespace ExpressionBuilder.Test 34 | { 35 | public class FirstLevel 36 | { 37 | public SecondLevel First { get; set; } 38 | public int Other { get; set; } 39 | } 40 | 41 | public class SecondLevel 42 | { 43 | public string Second { get; set; } 44 | } 45 | 46 | [TestClass] 47 | public class ExpressionUtilTest 48 | { 49 | [TestMethod] 50 | public void ReflectionShouldLoadCorrectTypeOnFirstLevel() 51 | { 52 | var type = ExpressionUtil.GetPropertyInfos(a => a.First).ToArray(); 53 | Assert.AreEqual(1, type.Length); 54 | Assert.AreEqual(typeof(SecondLevel), type[0].DataType); 55 | Assert.AreEqual("First", type[0].Name); 56 | } 57 | 58 | [TestMethod] 59 | public void ReflectionShouldLoadCorrectTypeOnSecondLevel() 60 | { 61 | var type = ExpressionUtil.GetPropertyInfos((a) => a.First.Second).ToArray(); 62 | Assert.AreEqual(2, type.Length); 63 | Assert.AreEqual(typeof(string), type[1].DataType); 64 | Assert.AreEqual(typeof(SecondLevel), type[0].DataType); 65 | Assert.AreEqual("Second", type[1].Name); 66 | Assert.AreEqual("First", type[0].Name); 67 | } 68 | 69 | 70 | [TestMethod] 71 | public void ReflectionShouldBuildTheCorrectExpressionOnFirstLevel() 72 | { 73 | 74 | var otherCompare = ExpressionUtil.GetComparer((a) => a.Other); 75 | 76 | var firstLevel = new FirstLevel { First = new SecondLevel { Second = "foo" }, Other = 2 }; 77 | 78 | var result = otherCompare(firstLevel, 2); 79 | Assert.IsTrue(result); 80 | result = otherCompare(firstLevel, 1); 81 | Assert.IsFalse(result); 82 | } 83 | 84 | [TestMethod] 85 | public void ReflectionShouldBuildTheCorrectExpressionOnSecondLevel() 86 | { 87 | var firstSecondCompare = ExpressionUtil.GetComparer((a) => a.First.Second); 88 | 89 | var firstLevel = new FirstLevel { First = new SecondLevel { Second = "foo" }, Other = 2 }; 90 | 91 | var result = firstSecondCompare(firstLevel, "foo"); 92 | Assert.IsTrue(result); 93 | result = firstSecondCompare(firstLevel, "bar"); 94 | Assert.IsFalse(result); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Diagnostics; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Operations; 32 | using Microsoft.VisualStudio.TestTools.UnitTesting; 33 | 34 | namespace ExpressionBuilder.Test 35 | { 36 | [TestClass] 37 | public class FunctionTest 38 | { 39 | [TestMethod] 40 | public void ItShouldBePossibleToDeclareParametersAndReturn() 41 | { 42 | const string expected = 43 | @"public System.String Call(System.String first, System.String second) 44 | { 45 | //No Operation; 46 | return first; 47 | }"; 48 | var newExpression = Function.Create() 49 | .WithParameter("first") 50 | .WithParameter("second") 51 | .WithBody(CodeLine.Nop) 52 | .Returns("first"); 53 | 54 | AssertString.AreEqual(expected, newExpression.ToString()); 55 | 56 | var lambda = newExpression.ToLambda>(); 57 | Assert.IsNotNull(lambda); 58 | 59 | Assert.AreEqual("test", lambda("test", "another")); 60 | } 61 | 62 | [TestMethod] 63 | public void CanBeCreatedAFunctionReturningVoid() 64 | { 65 | const string expected = 66 | @"public void Call(System.String first, System.String second) 67 | { 68 | //No Operation; 69 | }"; 70 | var newExpression = Function.Create() 71 | .WithParameter("first") 72 | .WithParameter("second") 73 | .WithBody(CodeLine.Nop); 74 | 75 | AssertString.AreEqual(expected, newExpression.ToString()); 76 | 77 | var lambda = newExpression.ToLambda>(); 78 | Assert.IsNotNull(lambda); 79 | 80 | lambda("test", "another"); 81 | } 82 | 83 | 84 | [TestMethod] 85 | public void CanBeCreatedAFunctionWithStaticClassMethodCall() 86 | { 87 | const string expected = 88 | @"public void Call() 89 | { 90 | System.Diagnostics.Debug.WriteLine(""Test""); 91 | }"; 92 | 93 | var classType = typeof(Debug); 94 | var newExpression = Function.Create() 95 | .WithBody(Operation.Invoke(classType, "WriteLine", new OperationConst("Test"))); 96 | 97 | Assert.AreEqual(expected, newExpression.ToString()); 98 | 99 | var lambda = newExpression.ToLambda(); 100 | Assert.IsNotNull(lambda); 101 | 102 | lambda(); 103 | } 104 | 105 | [TestMethod] 106 | public void CanBeCreatedAFunctionWithoutParametersAndReturn() 107 | { 108 | const string expected = 109 | @"public void Call() 110 | { 111 | //No Operation; 112 | }"; 113 | var newExpression = Function.Create() 114 | .WithBody(CodeLine.Nop); 115 | 116 | AssertString.AreEqual(expected, newExpression.ToString()); 117 | 118 | var lambda = newExpression.ToLambda(); 119 | Assert.IsNotNull(lambda); 120 | 121 | lambda(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/IfTest.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using Microsoft.VisualStudio.TestTools.UnitTesting; 30 | using ExpressionBuilder.Enums; 31 | using System.Linq.Expressions; 32 | 33 | namespace ExpressionBuilder.Test 34 | { 35 | [TestClass] 36 | public class IfTest 37 | { 38 | [TestMethod] 39 | public void IfThenElseIfShouldActCorrectly() 40 | { 41 | const string expected = 42 | @"public System.String Call(System.String par) 43 | { 44 | System.String result; 45 | if(par == ""then"") 46 | { 47 | result = ""then""; 48 | } 49 | else 50 | { 51 | if(par == ""elseif"") 52 | { 53 | result = ""elseif""; 54 | } 55 | else 56 | { 57 | result = ""else""; 58 | }; 59 | }; 60 | return result; 61 | }"; 62 | 63 | var newExpression = Function.Create() 64 | .WithParameter("par") 65 | .WithBody( 66 | CodeLine.CreateVariable("result"), 67 | CodeLine.CreateIf(Condition.CompareConst("par", "then")) 68 | .Then( 69 | CodeLine.AssignConstant("result", "then")) 70 | .ElseIf(Condition.Compare("par", Operation.Constant("elseif"))) 71 | .Then( 72 | CodeLine.AssignConstant("result", "elseif")) 73 | .Else( 74 | CodeLine.AssignConstant("result", "else")) 75 | ) 76 | .Returns("result"); 77 | 78 | AssertString.AreEqual(expected, newExpression.ToString()); 79 | 80 | var lambda = newExpression.ToLambda>(); 81 | Assert.IsNotNull(lambda); 82 | 83 | var result = lambda("then"); 84 | Assert.AreEqual("then", result); 85 | result = lambda("elseif"); 86 | Assert.AreEqual("elseif", result); 87 | result = lambda("else"); 88 | Assert.AreEqual("else", result); 89 | } 90 | 91 | [TestMethod] 92 | public void ReturnShouldBeHandledCorrectlyInsideIfs() 93 | { 94 | const string expected = 95 | @"public System.String Call(System.String par) 96 | { 97 | System.String result; 98 | if(par == ""then"") 99 | { 100 | result = ""then""; 101 | return result; 102 | } 103 | else 104 | { 105 | if(par == ""elseif"") 106 | { 107 | result = ""elseif""; 108 | return result; 109 | } 110 | else 111 | { 112 | result = ""else""; 113 | return result; 114 | }; 115 | }; 116 | return result; 117 | }"; 118 | 119 | var newExpression = Function.Create() 120 | .WithParameter("par") 121 | .WithBody( 122 | CodeLine.CreateVariable("result"), 123 | CodeLine.CreateIf(Condition.CompareConst("par", "then")) 124 | .Then( 125 | CodeLine.AssignConstant("result", "then"), 126 | CodeLine.Return()) 127 | .ElseIf(Condition.Compare("par",Operation.Constant("elseif"))) 128 | .Then( 129 | CodeLine.AssignConstant("result", "elseif"), 130 | CodeLine.Return()) 131 | .Else( 132 | CodeLine.AssignConstant("result", "else"), 133 | CodeLine.Return()) 134 | ) 135 | .Returns("result"); 136 | 137 | AssertString.AreEqual(expected, newExpression.ToString()); 138 | 139 | var lambda = newExpression.ToLambda>(); 140 | Assert.IsNotNull(lambda); 141 | 142 | var result = lambda("then"); 143 | Assert.AreEqual("then", result); 144 | result = lambda("elseif"); 145 | Assert.AreEqual("elseif", result); 146 | result = lambda("else"); 147 | Assert.AreEqual("else", result); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ExpressionBuilder.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Kendar.org")] 12 | [assembly: AssemblyProduct("ExpressionBuilder.Test")] 13 | [assembly: AssemblyCopyright("Copyright © Kendar.org 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ada987ff-2fed-4d7c-84b9-84df98812321")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/StringOperationTest.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using ExpressionBuilder.Enums; 30 | using Microsoft.VisualStudio.TestTools.UnitTesting; 31 | 32 | namespace ExpressionBuilder.Test 33 | { 34 | 35 | [TestClass] 36 | public class StringOperationTest 37 | { 38 | [TestMethod] 39 | public void ItShouldPossibleToInvokeToString() 40 | { 41 | const string expected = 42 | @"public System.String Call(System.Int32 par) 43 | { 44 | System.String result; 45 | result = par.ToString(); 46 | return result; 47 | }"; 48 | 49 | var newExpression = Function.Create() 50 | .WithParameter("par") 51 | .WithBody( 52 | CodeLine.CreateVariable("result"), 53 | CodeLine.Assign(Operation.Variable("result"), StringOperation.ToString("par")) 54 | ) 55 | .Returns("result"); 56 | 57 | AssertString.AreEqual(expected, newExpression.ToString()); 58 | 59 | var lambda = newExpression.ToLambda>(); 60 | Assert.IsNotNull(lambda); 61 | var result = lambda(1); 62 | Assert.AreEqual("1", result); 63 | } 64 | 65 | [TestMethod] 66 | public void ItShouldPossibleToInvokeStringCompare() 67 | { 68 | const string expected = 69 | @"public System.Int32 Call(System.String par1, System.String par2) 70 | { 71 | System.Int32 result; 72 | result = System.String.Compare(par1, par2, CurrentCulture); 73 | return result; 74 | }"; 75 | 76 | var newExpression = Function.Create() 77 | .WithParameter("par1") 78 | .WithParameter("par2") 79 | .WithBody( 80 | CodeLine.CreateVariable("result"), 81 | CodeLine.Assign(Operation.Variable("result"), StringOperation.Compare("par1", "par2")) 82 | ) 83 | .Returns("result"); 84 | 85 | AssertString.AreEqual(expected, newExpression.ToString()); 86 | 87 | var lambda = newExpression.ToLambda>(); 88 | Assert.IsNotNull(lambda); 89 | var result = lambda("a", "a"); 90 | Assert.AreEqual(0, result); 91 | result = lambda("a", "b"); 92 | Assert.AreEqual(-1, result); 93 | } 94 | 95 | [TestMethod] 96 | public void ItShouldPossibleToInvokeStringFormat() 97 | { 98 | const string expected = 99 | @"public System.String Call(System.String par1, System.String par2) 100 | { 101 | System.String result; 102 | result = System.String.Format(""{0}-{1}"", par1, par2); 103 | return result; 104 | }"; 105 | 106 | var newExpression = Function.Create() 107 | .WithParameter("par1") 108 | .WithParameter("par2") 109 | .WithBody( 110 | CodeLine.CreateVariable("result"), 111 | CodeLine.Assign(Operation.Variable("result"), 112 | StringOperation.Format( 113 | "{0}-{1}", 114 | Operation.Variable("par1"), 115 | Operation.Variable("par2"))) 116 | ) 117 | .Returns("result"); 118 | 119 | AssertString.AreEqual(expected, newExpression.ToString()); 120 | 121 | var lambda = newExpression.ToLambda>(); 122 | Assert.IsNotNull(lambda); 123 | var result = lambda("a", "b"); 124 | Assert.AreEqual("a-b", result); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/ToDoTest.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using System.Text; 32 | using Microsoft.VisualStudio.TestTools.UnitTesting; 33 | 34 | namespace ExpressionBuilder.Test 35 | { 36 | [TestClass] 37 | public class ToDoTest 38 | { 39 | [TestMethod] 40 | [Ignore] 41 | public void CollectionOperation_shouldWork() 42 | { 43 | 44 | } 45 | 46 | 47 | [TestMethod] 48 | [Ignore] 49 | public void MultiConditins_shouldWork() 50 | { 51 | 52 | } 53 | 54 | [TestMethod] 55 | [Ignore] 56 | public void ReflectionUtil_shouldWork() 57 | { 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/WhileTest.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using ExpressionBuilder.Enums; 30 | using ExpressionBuilder.Utils; 31 | using Microsoft.VisualStudio.TestTools.UnitTesting; 32 | 33 | namespace ExpressionBuilder.Test 34 | { 35 | [TestClass] 36 | public class WhileTest 37 | { 38 | [TestMethod] 39 | public void WhileLoop() 40 | { 41 | const string expected = 42 | @"public System.Int32 Call(System.Int32 par) 43 | { 44 | System.Int32 first; 45 | first = 0; 46 | while(first < par) 47 | { 48 | first += 1; 49 | }; 50 | return first; 51 | }"; 52 | 53 | var newExpression = Function.Create() 54 | .WithParameter("par") 55 | .WithBody( 56 | CodeLine.CreateVariable("first"), 57 | CodeLine.AssignConstant("first", 0), 58 | CodeLine.CreateWhile(Condition.Compare("first", "par", ComparaisonOperator.Smaller)) 59 | .Do( 60 | CodeLine.AssignConstant("first", Operation.Constant(1), AssignementOperator.SumAssign) 61 | ) 62 | ) 63 | .Returns("first"); 64 | 65 | AssertString.AreEqual(expected, newExpression.ToString()); 66 | 67 | var lambda = newExpression.ToLambda>(); 68 | Assert.IsNotNull(lambda); 69 | 70 | var result = lambda(4); 71 | Assert.AreEqual(4, result); 72 | 73 | result = lambda(2); 74 | Assert.AreEqual(2, result); 75 | } 76 | 77 | [TestMethod] 78 | public void WhileLoopShouldAllowForcedReturn() 79 | { 80 | const string expected = 81 | @"public System.Int32 Call(System.Int32 par) 82 | { 83 | System.Int32 first; 84 | first = 0; 85 | while(first < par) 86 | { 87 | first += 1; 88 | if(first >= 10) 89 | { 90 | return first; 91 | }; 92 | }; 93 | return first; 94 | }"; 95 | 96 | var newExpression = Function.Create() 97 | .WithParameter("par") 98 | .WithBody( 99 | CodeLine.CreateVariable("first"), 100 | CodeLine.AssignConstant("first", 0), 101 | CodeLine.CreateWhile(Condition.Compare("first", "par", ComparaisonOperator.Smaller)) 102 | .Do( 103 | CodeLine.AssignConstant("first", Operation.Constant(1), AssignementOperator.SumAssign), 104 | CodeLine.CreateIf(Condition.CompareConst("first",10,ComparaisonOperator.GreaterEqual)) 105 | .Then( 106 | CodeLine.Return() 107 | )) 108 | ) 109 | .Returns("first"); 110 | 111 | AssertString.AreEqual(expected, newExpression.ToString()); 112 | 113 | var lambda = newExpression.ToLambda>(); 114 | Assert.IsNotNull(lambda); 115 | 116 | var result = lambda(4); 117 | Assert.AreEqual(4, result); 118 | 119 | result = lambda(20); 120 | Assert.AreEqual(10, result); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31010.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpressionBuilder.Test", "ExpressionBuilder.Test\ExpressionBuilder.Test.csproj", "{499EAC63-E44E-48B6-85C4-5F6E5D2185E3}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{BAB02ADF-B910-418C-BD4D-D76B5EA633E7}" 9 | ProjectSection(SolutionItems) = preProject 10 | .nuget\NuGet.Config = .nuget\NuGet.Config 11 | .nuget\NuGet.exe = .nuget\NuGet.exe 12 | .nuget\NuGet.targets = .nuget\NuGet.targets 13 | EndProjectSection 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpressionBuilder", "ExpressionBuilder\ExpressionBuilder.csproj", "{F333183C-4688-4FA2-8346-DD62CBCF2896}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Release|Any CPU = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {499EAC63-E44E-48B6-85C4-5F6E5D2185E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {499EAC63-E44E-48B6-85C4-5F6E5D2185E3}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {499EAC63-E44E-48B6-85C4-5F6E5D2185E3}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {499EAC63-E44E-48B6-85C4-5F6E5D2185E3}.Release|Any CPU.Build.0 = Release|Any CPU 27 | {F333183C-4688-4FA2-8346-DD62CBCF2896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {F333183C-4688-4FA2-8346-DD62CBCF2896}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {F333183C-4688-4FA2-8346-DD62CBCF2896}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {F333183C-4688-4FA2-8346-DD62CBCF2896}.Release|Any CPU.Build.0 = Release|Any CPU 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLine.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using ExpressionBuilder.CodeLines; 30 | using ExpressionBuilder.Enums; 31 | using ExpressionBuilder.Fluent; 32 | 33 | namespace ExpressionBuilder 34 | { 35 | public static class CodeLine 36 | { 37 | public static ICodeLine CreateVariable(Type dataType, string variableName) 38 | { 39 | return new CreateVariable(new Variable(dataType, variableName)); 40 | } 41 | 42 | 43 | public static ICodeLine CreateVariable(string variableName) 44 | { 45 | return CreateVariable(typeof(TData), variableName); 46 | } 47 | 48 | public static ICodeLine AssignConstant(string lVariableName, object rConst, AssignementOperator assignType = AssignementOperator.Assign) 49 | { 50 | return Assign(Operation.Variable(lVariableName), Operation.Constant(rConst), assignType); 51 | } 52 | 53 | public static ICodeLine AssignConstant(ILeftable lValue, object rConst, AssignementOperator assignType = AssignementOperator.Assign) 54 | { 55 | return Assign(lValue, Operation.Constant(rConst), assignType); 56 | } 57 | 58 | public static ICodeLine Assign(ILeftable lValue, IRightable rValue, AssignementOperator assignType = AssignementOperator.Assign) 59 | { 60 | return new Assign(lValue, rValue, assignType); 61 | } 62 | 63 | public static ICodeLine Assign(string lVariableName, string rVariableName, AssignementOperator assignType = AssignementOperator.Assign) 64 | { 65 | return Assign(Operation.Variable(lVariableName), Operation.Variable(rVariableName), assignType); 66 | } 67 | 68 | public static ICodeLine Assign(ILeftable lValue, string rVariableName, AssignementOperator assignType = AssignementOperator.Assign) 69 | { 70 | return Assign(lValue, Operation.Variable(rVariableName), assignType); 71 | } 72 | 73 | public static ICodeLine Assign(string lVariableName, IRightable rValue, AssignementOperator assignType = AssignementOperator.Assign) 74 | { 75 | return Assign(Operation.Variable(lVariableName), rValue, assignType); 76 | } 77 | 78 | public static IIf CreateIf(Condition condition) 79 | { 80 | return new If(condition); 81 | } 82 | 83 | 84 | public static IWhile CreateWhile(Condition condition) 85 | { 86 | return new While(condition); 87 | } 88 | 89 | public static ICodeLine Return() 90 | { 91 | return new CreateReturn(); 92 | } 93 | 94 | public static ICodeLine Nop 95 | { 96 | get 97 | { 98 | return new Nop(); 99 | } 100 | 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLines/Assign.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.ComponentModel; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Enums; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Parser; 34 | 35 | namespace ExpressionBuilder.CodeLines 36 | { 37 | 38 | public class Assign : ICodeLine 39 | { 40 | internal ILeftable LValue; 41 | internal IRightable RValue; 42 | internal AssignementOperator AssignType; 43 | 44 | public Assign(ILeftable lvalue, IRightable rValue, AssignementOperator assignType) 45 | { 46 | LValue = lvalue; 47 | RValue = rValue; 48 | AssignType = assignType; 49 | } 50 | 51 | public string ToString(ParseContext context) 52 | { 53 | var rstring = RValue.ToString(context); 54 | var lstring = LValue.ToString(context); 55 | return lstring + " " + AssignementToString() + " " + rstring; 56 | } 57 | 58 | public void PreParseExpression(ParseContext context) 59 | { 60 | RValue.PreParseExpression(context); 61 | LValue.PreParseExpression(context); 62 | 63 | ParsedType = LValue.ParsedType; 64 | } 65 | 66 | public Type ParsedType { get; private set; } 67 | 68 | private string AssignementToString() 69 | { 70 | switch (AssignType) 71 | { 72 | case (AssignementOperator.Assign): 73 | return "="; 74 | case (AssignementOperator.MultiplyAssign): 75 | return "*="; 76 | case (AssignementOperator.SubtractAssign): 77 | return "-="; 78 | case (AssignementOperator.SumAssign): 79 | return "+="; 80 | } 81 | throw new InvalidEnumArgumentException(); 82 | } 83 | 84 | 85 | public Expression ToExpression(ParseContext context) 86 | { 87 | switch (AssignType) 88 | { 89 | case (AssignementOperator.Assign): 90 | { 91 | //if (RValue.ParsedType.IsValueType) 92 | { 93 | return Expression.Assign(LValue.ToExpression(context),Expression.Convert(RValue.ToExpression(context),LValue.ParsedType)); 94 | } 95 | //return Expression.Assign(LValue.ToExpression(context), RValue.ToExpression(context)); 96 | } 97 | case (AssignementOperator.MultiplyAssign): 98 | return Expression.MultiplyAssign(LValue.ToExpression(context), RValue.ToExpression(context)); 99 | case (AssignementOperator.SubtractAssign): 100 | return Expression.SubtractAssign(LValue.ToExpression(context), RValue.ToExpression(context)); 101 | case (AssignementOperator.SumAssign): 102 | { 103 | if (LValue.ParsedType == typeof(string) || RValue.ParsedType == typeof(string)) 104 | { 105 | Expression> func = ((a, b) => SumAssign(a, b)); 106 | return Expression.Assign(LValue.ToExpression(context), 107 | Expression.Invoke(func, LValue.ToExpression(context), RValue.ToExpression(context))); 108 | 109 | } 110 | return Expression.AddAssign(LValue.ToExpression(context), RValue.ToExpression(context)); 111 | } 112 | } 113 | throw new InvalidEnumArgumentException(); 114 | } 115 | 116 | private static string SumAssign(object a, object b) 117 | { 118 | // ReSharper disable RedundantToStringCall 119 | return a.ToString() + b.ToString(); 120 | // ReSharper restore RedundantToStringCall 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLines/CreateReturn.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | using ExpressionBuilder.Fluent; 31 | using ExpressionBuilder.Parser; 32 | 33 | namespace ExpressionBuilder.CodeLines 34 | { 35 | public class CreateReturn : ICodeLine 36 | { 37 | internal CreateReturn() 38 | { 39 | ParsedType = null; 40 | } 41 | 42 | public string ToString(ParseContext context) 43 | { 44 | if (!string.IsNullOrWhiteSpace(context.ReturnVariable)) 45 | { 46 | return "return " + context.ReturnVariable; 47 | } 48 | return "return"; 49 | } 50 | 51 | public Expression ToExpression(ParseContext context) 52 | { 53 | return Expression.Goto(context.ReturnLabel); 54 | } 55 | 56 | public void PreParseExpression(ParseContext context) 57 | { 58 | 59 | } 60 | 61 | public Type ParsedType { get; private set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLines/CreateVariable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | using ExpressionBuilder.Fluent; 31 | using ExpressionBuilder.Parser; 32 | using ExpressionBuilder.Utils; 33 | 34 | namespace ExpressionBuilder.CodeLines 35 | { 36 | public class CreateVariable : ICodeLine 37 | { 38 | internal Variable VariableDeclaration; 39 | 40 | public CreateVariable(Variable variable) 41 | { 42 | VariableDeclaration = variable; 43 | } 44 | 45 | public string ToString(ParseContext context) 46 | { 47 | return ReflectionUtil.TypeToString(VariableDeclaration.DataType) + " " + VariableDeclaration.Name; 48 | } 49 | 50 | public void PreParseExpression(ParseContext context) 51 | { 52 | context.Current.AddVariable(VariableDeclaration); 53 | ParsedType = VariableDeclaration.DataType; 54 | } 55 | 56 | public Type ParsedType { get; private set; } 57 | 58 | public Expression ToExpression(ParseContext context) 59 | { 60 | context.Current.AddVariable(VariableDeclaration); 61 | VariableDeclaration.Expression = Expression.Variable(VariableDeclaration.DataType, VariableDeclaration.Name); 62 | return VariableDeclaration.Expression; 63 | } 64 | 65 | internal Expression DefaultInitialize(ParseContext context) 66 | { 67 | if (VariableDeclaration.Expression == null) 68 | { 69 | VariableDeclaration.Expression = ToExpression(context); 70 | } 71 | return Expression.Assign(VariableDeclaration.Expression, Expression.Default(VariableDeclaration.DataType)); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLines/Nop.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | using System; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Fluent; 32 | using ExpressionBuilder.Parser; 33 | 34 | namespace ExpressionBuilder.CodeLines 35 | { 36 | public class Nop : ICodeLine 37 | { 38 | public string ToString(ParseContext context) 39 | { 40 | return "//No Operation"; 41 | } 42 | 43 | public Expression ToExpression(ParseContext context) 44 | { 45 | return Expression.Empty(); 46 | } 47 | 48 | public void PreParseExpression(ParseContext context) 49 | { 50 | 51 | } 52 | 53 | public Type ParsedType { get { return null; } } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLines/OperationAction.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Fluent; 32 | using ExpressionBuilder.Parser; 33 | using ExpressionBuilder.Utils; 34 | 35 | namespace ExpressionBuilder.CodeLines 36 | { 37 | public class OperationActionBase : ICodeLine 38 | { 39 | protected Expression LambdaExpression; 40 | internal object ActionInstance; 41 | internal IOperation[] Parameters; 42 | protected OperationActionBase(object action, IOperation[] parameters) 43 | { 44 | ActionInstance = action; 45 | Parameters = parameters; 46 | ParsedType = null; 47 | } 48 | 49 | public string ToString(ParseContext context) 50 | { 51 | //var ActiontionTypes = ActionInstance.GetType().GenericTypeArguments; 52 | var dataType = ReflectionUtil.TypeToString(ActionInstance.GetType()); 53 | var result = "Lambda<" + dataType + ">("; 54 | for (int i = 0; i < Parameters.Length; i++) 55 | { 56 | if (i > 0) result += ", "; 57 | result += Parameters[i].ToString(context); 58 | } 59 | return result + ")"; 60 | } 61 | 62 | public Expression ToExpression(ParseContext context) 63 | { 64 | var pars = new List(); 65 | foreach (var p in Parameters) 66 | { 67 | pars.Add(p.ToExpression(context)); 68 | } 69 | 70 | return Expression.Invoke(LambdaExpression, pars); 71 | } 72 | 73 | public void PreParseExpression(ParseContext context) 74 | { 75 | for (int i = 0; i < Parameters.Length; i++) 76 | { 77 | Parameters[i].PreParseExpression(context); 78 | } 79 | } 80 | 81 | public Type ParsedType { get; protected set; } 82 | } 83 | 84 | public class OperationAction : OperationActionBase 85 | { 86 | public OperationAction(Action action, IOperation[] parameters) 87 | : base(action, parameters) 88 | { 89 | if (parameters.Length != 1) throw new ArgumentException(); 90 | Expression> lambda = ((a) => action(a)); 91 | LambdaExpression = lambda; 92 | } 93 | } 94 | 95 | public class OperationAction : OperationActionBase 96 | { 97 | public OperationAction(Action action, IOperation[] parameters) 98 | : base(action, parameters) 99 | { 100 | if (parameters.Length != 2) throw new ArgumentException(); 101 | Expression> lambda = ((p1, p2) => action(p1, p2)); 102 | LambdaExpression = lambda; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CodeLines/OperationInvoke.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using System.Reflection; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Operations; 34 | using ExpressionBuilder.Parser; 35 | using ExpressionBuilder.Utils; 36 | 37 | namespace ExpressionBuilder.CodeLines 38 | { 39 | public class OperationInvoke : IOperation, ICodeLine 40 | { 41 | internal IOperation Variable; 42 | internal string MethodName; 43 | internal IOperation[] Parameters; 44 | internal readonly Type StaticDataType; 45 | 46 | public OperationInvoke(IOperation variable, string methodName, IOperation[] parameters) 47 | { 48 | Variable = variable; 49 | MethodName = methodName; 50 | Parameters = parameters; 51 | } 52 | 53 | public OperationInvoke(Type dataType, string methodName, IOperation[] parameters) 54 | { 55 | MethodName = methodName; 56 | Parameters = parameters; 57 | StaticDataType = dataType; 58 | } 59 | 60 | public string ToString(ParseContext context) 61 | { 62 | var result = string.Empty; 63 | if (StaticDataType == null) 64 | { 65 | result = Variable.ToString(context); 66 | } 67 | else 68 | { 69 | result = ReflectionUtil.TypeToString(StaticDataType); 70 | } 71 | result += "." + MethodName + "("; 72 | for (int i = 0; i < Parameters.Length; i++) 73 | { 74 | if (i > 0) result += ", "; 75 | result += Parameters[i].ToString(context); 76 | } 77 | return result + ")"; 78 | } 79 | 80 | 81 | 82 | private List _paramTypes; 83 | 84 | public void PreParseExpression(ParseContext context) 85 | { 86 | _paramTypes = new List(); 87 | for (int i = 0; i < Parameters.Length; i++) 88 | { 89 | Parameters[i].PreParseExpression(context); 90 | _paramTypes.Add(Parameters[i].ParsedType); 91 | } 92 | 93 | ParsedType = null; 94 | } 95 | public Type ParsedType { get; private set; } 96 | 97 | public Expression ToExpression(ParseContext context) 98 | { 99 | var pars = new List(); 100 | 101 | foreach (var param in Parameters) 102 | { 103 | pars.Add(param.ToExpression(context)); 104 | } 105 | 106 | Type type = StaticDataType; 107 | if (StaticDataType == null) 108 | { 109 | type = Variable.ParsedType; 110 | if (Variable is OperationVariable) 111 | { 112 | var variable = context.GetVariable(((OperationVariable)Variable).Name); 113 | type = variable.DataType; 114 | } 115 | } 116 | 117 | var method = ReflectionUtil.GetMethod(type, MethodName, _paramTypes); 118 | 119 | if (method.GoodFrom >= 0) 120 | { 121 | var startDefault = method.GoodFrom; 122 | while (startDefault < method.ParamValues.Count) 123 | { 124 | pars.Add(Operation.Constant(method.ParamValues[method.GoodFrom]).ToExpression(context)); 125 | startDefault++; 126 | } 127 | } 128 | var my = (MethodInfo)method.Method; 129 | if ((my.Attributes & MethodAttributes.Static) == 0) 130 | { 131 | return Expression.Call(Variable.ToExpression(context), method.Method as MethodInfo, pars); 132 | } 133 | return Expression.Call(method.Method as MethodInfo, pars); 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/CollectionOperation.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using ExpressionBuilder.Fluent; 31 | 32 | namespace ExpressionBuilder 33 | { 34 | public static class CollectionOperation 35 | { 36 | public static IRightable CreateDictionary(Type key, Type value) 37 | { 38 | var dType = typeof(Dictionary).MakeGenericType(new[] { key, value }); 39 | return Operation.CreateInstance(dType); 40 | } 41 | 42 | public static IRightable CreateDictionary() 43 | { 44 | return CreateDictionary(typeof(TKey), typeof(TVal)); 45 | } 46 | 47 | public static IRightable CreateList(Type value) 48 | { 49 | var dType = typeof(List).MakeGenericType(new[] { value }); 50 | return Operation.CreateInstance(dType); 51 | } 52 | 53 | public static IRightable CreateList< TVal>() 54 | { 55 | return CreateList(typeof(TVal)); 56 | } 57 | 58 | public static IRightable Count(IOperation variable) 59 | { 60 | return Operation.Get(variable, "Count"); 61 | } 62 | 63 | public static IRightable Count(string variable) 64 | { 65 | return Count(Operation.Variable(variable)); 66 | } 67 | 68 | public static IRightable Count(object value) 69 | { 70 | return Count(Operation.Constant(value)); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Condition.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | using ExpressionBuilder.Conditions; 31 | using ExpressionBuilder.Enums; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Parser; 34 | 35 | namespace ExpressionBuilder 36 | { 37 | public abstract class Condition : IParsable, IRightable 38 | { 39 | 40 | public static Condition And(params Condition[] subConditions) 41 | { 42 | return new MultiCondition(true, subConditions); 43 | } 44 | 45 | public static Condition Or(params Condition[] subConditions) 46 | { 47 | return new MultiCondition(false, subConditions); 48 | } 49 | 50 | public static Condition Compare(string lVariableName, string rVariableName, ComparaisonOperator comparaison = ComparaisonOperator.Equal) 51 | { 52 | return Compare(Operation.Variable(lVariableName), Operation.Variable(rVariableName), comparaison); 53 | } 54 | 55 | public static Condition Compare(IOperation lValue, string rVariableName, ComparaisonOperator comparaison = ComparaisonOperator.Equal) 56 | { 57 | return Compare(lValue, Operation.Variable(rVariableName), comparaison); 58 | } 59 | 60 | public static Condition Compare(string lVariableName, IOperation rValue, ComparaisonOperator comparaison = ComparaisonOperator.Equal) 61 | { 62 | return Compare(Operation.Variable(lVariableName), rValue, comparaison); 63 | } 64 | 65 | public static Condition Compare(IOperation lValue, IOperation rValue, ComparaisonOperator comparaison = ComparaisonOperator.Equal) 66 | { 67 | return new BinaryCondition(lValue, rValue, comparaison); 68 | } 69 | 70 | 71 | public static Condition CompareConst(string lVariableName, object rValue, ComparaisonOperator comparaison = ComparaisonOperator.Equal) 72 | { 73 | return Compare(Operation.Variable(lVariableName), Operation.Constant(rValue), comparaison); 74 | } 75 | 76 | public static Condition CompareConst(IOperation lValue, object rValue, ComparaisonOperator comparaison = ComparaisonOperator.Equal) 77 | { 78 | return Compare(lValue, Operation.Constant(rValue), comparaison); 79 | } 80 | 81 | protected Condition() 82 | { 83 | } 84 | 85 | public abstract string ToString(ParseContext context); 86 | public abstract Expression ToExpression(ParseContext context); 87 | public abstract void PreParseExpression(ParseContext context); 88 | public abstract Type ParsedType { get; protected set; } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Conditions/BinaryCondition.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.ComponentModel; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Enums; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Parser; 34 | 35 | namespace ExpressionBuilder.Conditions 36 | { 37 | public class BinaryCondition : Condition 38 | { 39 | internal IOperation LValue; 40 | internal IOperation RValue; 41 | internal ComparaisonOperator Comparaison; 42 | 43 | public BinaryCondition(IOperation lValue, IOperation rValue, ComparaisonOperator comparaison) 44 | { 45 | LValue = lValue; 46 | RValue = rValue; 47 | Comparaison = comparaison; 48 | } 49 | 50 | public override string ToString(ParseContext context) 51 | { 52 | var rstring = RValue.ToString(context); 53 | var lstring = LValue.ToString(context); 54 | return lstring + " " + AssignementToString() + " " + rstring; 55 | } 56 | 57 | protected Type _rType; 58 | protected Type _lType; 59 | public override void PreParseExpression(ParseContext context) 60 | { 61 | RValue.PreParseExpression(context); 62 | _rType = RValue.ParsedType; 63 | LValue.PreParseExpression(context); 64 | _lType = LValue.ParsedType; 65 | ParsedType = typeof(bool); 66 | } 67 | 68 | public override Type ParsedType { get; protected set; } 69 | 70 | private string AssignementToString() 71 | { 72 | switch (Comparaison) 73 | { 74 | case (ComparaisonOperator.Different): 75 | return "!="; 76 | case (ComparaisonOperator.Equal): 77 | return "=="; 78 | case (ComparaisonOperator.Greater): 79 | return ">"; 80 | case (ComparaisonOperator.GreaterEqual): 81 | return ">="; 82 | case (ComparaisonOperator.Smaller): 83 | return "<"; 84 | case (ComparaisonOperator.SmallerEqual): 85 | return "<="; 86 | case (ComparaisonOperator.ReferenceEqual): 87 | return "=="; 88 | } 89 | throw new InvalidEnumArgumentException(); 90 | } 91 | 92 | public override Expression ToExpression(ParseContext context) 93 | { 94 | switch (Comparaison) 95 | { 96 | case (ComparaisonOperator.Different): 97 | return Expression.NotEqual(LValue.ToExpression(context), RValue.ToExpression(context)); 98 | case (ComparaisonOperator.Equal): 99 | return Expression.Equal(LValue.ToExpression(context), RValue.ToExpression(context)); 100 | case (ComparaisonOperator.Greater): 101 | return Expression.GreaterThan(LValue.ToExpression(context), RValue.ToExpression(context)); 102 | case (ComparaisonOperator.GreaterEqual): 103 | return Expression.GreaterThanOrEqual(LValue.ToExpression(context), RValue.ToExpression(context)); 104 | case (ComparaisonOperator.Smaller): 105 | return Expression.LessThan(LValue.ToExpression(context), RValue.ToExpression(context)); 106 | case (ComparaisonOperator.SmallerEqual): 107 | return Expression.LessThanOrEqual(LValue.ToExpression(context), RValue.ToExpression(context)); 108 | case (ComparaisonOperator.ReferenceEqual): 109 | return Expression.ReferenceEqual(LValue.ToExpression(context), RValue.ToExpression(context)); 110 | } 111 | throw new InvalidEnumArgumentException(); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Conditions/MultiCondition.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Parser; 32 | 33 | namespace ExpressionBuilder.Conditions 34 | { 35 | public class MultiCondition : Condition 36 | { 37 | internal bool IsAnd; 38 | internal List SubConditions; 39 | 40 | public MultiCondition(bool isAnd, params Condition[] subConditions) 41 | { 42 | IsAnd = isAnd; 43 | SubConditions = new List(subConditions); 44 | } 45 | 46 | public override string ToString(ParseContext context) 47 | { 48 | var res = "("; 49 | var operation = IsAnd ? "&&" : "||"; 50 | for (int i = 0; i < SubConditions.Count; i++) 51 | { 52 | if (i > 0) res += operation; 53 | res += SubConditions[i].ToString(context); 54 | } 55 | return res + ")"; 56 | } 57 | 58 | public override void PreParseExpression(ParseContext context) 59 | { 60 | for (int i = 0; i < SubConditions.Count; i++) 61 | { 62 | SubConditions[i].PreParseExpression(context); 63 | } 64 | ParsedType = typeof(bool); 65 | } 66 | 67 | public override Expression ToExpression(ParseContext context) 68 | { 69 | Expression result = null; 70 | for (int index = (SubConditions.Count - 2); index >= 0; index--) 71 | { 72 | if (result == null) 73 | { 74 | var l = SubConditions[index].ToExpression(context); 75 | var r = SubConditions[index + 1].ToExpression(context); 76 | result = BuildOperation(l, r); 77 | } 78 | else 79 | { 80 | var l = SubConditions[index].ToExpression(context); 81 | result = BuildOperation(l, result); 82 | } 83 | } 84 | return result; 85 | } 86 | 87 | private Expression BuildOperation(Expression l, Expression r) 88 | { 89 | if (IsAnd) 90 | { 91 | return Expression.AndAlso(l, r); 92 | } 93 | 94 | return Expression.OrElse(l, r); 95 | } 96 | 97 | public override Type ParsedType { get; protected set; } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Enums/AssignementOperators.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Enums 30 | { 31 | public enum AssignementOperator 32 | { 33 | Assign, 34 | SumAssign, 35 | SubtractAssign, 36 | MultiplyAssign 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Enums/ComparaisonOperator.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Enums 30 | { 31 | public enum ComparaisonOperator 32 | { 33 | Equal, 34 | Different, 35 | Greater, 36 | GreaterEqual, 37 | Smaller, 38 | SmallerEqual, 39 | ReferenceEqual 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/ExpressionBuilder.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F333183C-4688-4FA2-8346-DD62CBCF2896} 8 | Library 9 | Properties 10 | ExpressionBuilder 11 | ExpressionBuilder 12 | v4.5 13 | 15 | 512 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | 28 | 29 | pdbonly 30 | bin\Release\ 31 | true 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | Designer 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/ExpressionBuilder.nuspec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/ExpressionBuilder/ExpressionBuilder.nuspec -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IBodyOrParameter.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IBodyOrParameter : IFunctionBody, IFunctionParameter 32 | { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/ICodeLine.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using ExpressionBuilder.Parser; 29 | 30 | namespace ExpressionBuilder.Fluent 31 | { 32 | public interface ICodeLine : IParsable 33 | { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IElseIf.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IElseIf 32 | { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IExpressionResult.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System.Linq.Expressions; 29 | 30 | namespace ExpressionBuilder.Fluent 31 | { 32 | public interface IExpressionResult 33 | { 34 | LambdaExpression ToExpression(); 35 | TData ToLambda() where TData : class; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IFunctionBody.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IFunctionBody 32 | { 33 | IFunctionReturn WithBody(ICodeLine firstCodeLine, params ICodeLine[] codeLines); 34 | //IFluentCodeLine WithFluentBody(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IFunctionParameter.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | 30 | namespace ExpressionBuilder.Fluent 31 | { 32 | public interface IFunctionParameter 33 | { 34 | IBodyOrParameter WithParameter(Type type, string name); 35 | IBodyOrParameter WithParameter(string name); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IFunctionReturn.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IFunctionReturn : IExpressionResult 32 | { 33 | IExpressionResult Returns(string variableName); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IIf.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IIf 32 | { 33 | IIfThen Then(ICodeLine firstCodeLine, params ICodeLine[] codeLines); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IIfThen.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IIfThen : ICodeLine 32 | { 33 | IIf ElseIf(Condition elseIfCondition); 34 | ICodeLine Else(ICodeLine firstCodeLine, params ICodeLine[] codeLines); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/ILeftRightable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | namespace ExpressionBuilder.Fluent 29 | { 30 | public interface ILeftRightable : ILeftable, IRightable 31 | { 32 | } 33 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/ILeftable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface ILeftable : IOperation 32 | { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IOperation.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using ExpressionBuilder.Parser; 29 | 30 | namespace ExpressionBuilder.Fluent 31 | { 32 | public interface IOperation : IParsable 33 | { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IRightable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | namespace ExpressionBuilder.Fluent 29 | { 30 | public interface IRightable : IOperation 31 | { 32 | } 33 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Fluent/IWhile.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | 29 | namespace ExpressionBuilder.Fluent 30 | { 31 | public interface IWhile 32 | { 33 | ICodeLine Do(ICodeLine firstCodeLine, params ICodeLine[] codeLines); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/If.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Fluent; 32 | using ExpressionBuilder.Parser; 33 | using ExpressionBuilder.CodeLines; 34 | 35 | namespace ExpressionBuilder 36 | { 37 | public class If : IIf, IIfThen 38 | { 39 | internal If ParentIf; 40 | internal List ThenCodeLines; 41 | internal List ElseCodeLines; 42 | internal Condition Condition; 43 | 44 | internal If(Condition condition, If parentIf = null) 45 | { 46 | ParentIf = parentIf; 47 | if (condition == null) throw new ArgumentException(); 48 | Condition = condition; 49 | ThenCodeLines = new List(); 50 | ElseCodeLines = new List(); 51 | } 52 | 53 | public IIfThen Then(ICodeLine firstCodeLine, params ICodeLine[] codeLines) 54 | { 55 | ThenCodeLines.Add(firstCodeLine); 56 | foreach (var codeLine in codeLines) 57 | { 58 | ThenCodeLines.Add(codeLine); 59 | } 60 | return this; 61 | } 62 | 63 | public IIf ElseIf(Condition elseIfCondition) 64 | { 65 | var elseIf = new If(elseIfCondition, this); 66 | ElseCodeLines.Add(elseIf); 67 | return elseIf; 68 | } 69 | 70 | public ICodeLine Else(ICodeLine firstCodeLine, params ICodeLine[] codeLines) 71 | { 72 | ElseCodeLines.Add(firstCodeLine); 73 | foreach (var codeLine in codeLines) 74 | { 75 | ElseCodeLines.Add(codeLine); 76 | } 77 | return this; 78 | } 79 | 80 | public string ToString(ParseContext context) 81 | { 82 | var result = "if(" + Condition.ToString(context) + ")\n"; 83 | result += context.Pad + "{\n"; 84 | context.AddLevel(); 85 | 86 | foreach (var line in ThenCodeLines) 87 | { 88 | var createVariable = line as CreateVariable; 89 | if (createVariable != null) 90 | { 91 | createVariable.DefaultInitialize(context); 92 | } 93 | result += context.Pad + line.ToString(context) + ";\n"; 94 | } 95 | 96 | context.RemoveLevel(); 97 | result += context.Pad + "}"; 98 | if (ElseCodeLines.Count > 0) 99 | { 100 | result += context.Pad + "\n"; 101 | result += context.Pad + "else\n"; 102 | result += context.Pad + "{\n"; 103 | context.AddLevel(); 104 | 105 | foreach (var line in ElseCodeLines) 106 | { 107 | var createVariable = line as CreateVariable; 108 | if (createVariable != null) 109 | { 110 | createVariable.DefaultInitialize(context); 111 | } 112 | result += context.Pad + line.ToString(context) + ";\n"; 113 | } 114 | 115 | context.RemoveLevel(); 116 | result += context.Pad + "}"; 117 | } 118 | return result; 119 | } 120 | 121 | public void PreParseExpression(ParseContext context) 122 | { 123 | //var pl = context.Current; 124 | Condition.PreParseExpression(context); 125 | context.AddLevel(); 126 | 127 | foreach (var line in ThenCodeLines) 128 | { 129 | line.PreParseExpression(context); 130 | } 131 | 132 | context.RemoveLevel(); 133 | 134 | if (ElseCodeLines.Count > 0) 135 | { 136 | context.AddLevel(); 137 | 138 | foreach (var line in ElseCodeLines) 139 | { 140 | line.PreParseExpression(context); 141 | } 142 | 143 | context.RemoveLevel(); 144 | } 145 | } 146 | 147 | public Type ParsedType { get; private set; } 148 | 149 | public Expression ToExpression(ParseContext context) 150 | { 151 | var conditionExpression = Condition.ToExpression(context); 152 | context.AddLevel(); 153 | 154 | var thenLine = new List(); 155 | var listOfThenVars = new List(); 156 | foreach (var line in ThenCodeLines) 157 | { 158 | var expLine = line.ToExpression(context); 159 | 160 | var createVariable = line as CreateVariable; 161 | if (createVariable != null) 162 | { 163 | listOfThenVars.Add((ParameterExpression)expLine); 164 | expLine = createVariable.DefaultInitialize(context); 165 | } 166 | thenLine.Add(expLine); 167 | } 168 | var thenBlock = Expression.Block(listOfThenVars.ToArray(), thenLine); 169 | 170 | context.RemoveLevel(); 171 | 172 | var elseLine = new List(); 173 | if (ElseCodeLines.Count > 0) 174 | { 175 | context.AddLevel(); 176 | var listOfElseVars = new List(); 177 | foreach (var line in ElseCodeLines) 178 | { 179 | var expLine = line.ToExpression(context); 180 | 181 | var createVariable = line as CreateVariable; 182 | if (createVariable != null) 183 | { 184 | listOfElseVars.Add((ParameterExpression)expLine); 185 | expLine = createVariable.DefaultInitialize(context); 186 | } 187 | elseLine.Add(expLine); 188 | } 189 | 190 | context.RemoveLevel(); 191 | var elseBlock = Expression.Block(listOfElseVars, elseLine); 192 | return Expression.IfThenElse(conditionExpression, thenBlock, elseBlock); 193 | } 194 | return Expression.IfThen(conditionExpression, thenBlock); 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operation.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using ExpressionBuilder.CodeLines; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Operations; 34 | 35 | namespace ExpressionBuilder 36 | { 37 | public class Operation 38 | { 39 | public static ILeftRightable Variable(string name) 40 | { 41 | return new OperationVariable(name); 42 | } 43 | 44 | public static IRightable Constant(object value) 45 | { 46 | if (value is OperationConst) 47 | { 48 | return value as OperationConst; 49 | } 50 | return new OperationConst(value); 51 | } 52 | 53 | public static IRightable InvokeReturn(IOperation variable, string methodName, params IOperation[] parameters) 54 | { 55 | return new OperationInvokeReturn(variable, methodName, parameters); 56 | } 57 | 58 | public static IRightable InvokeReturn(string variable, string methodName, params IOperation[] parameters) 59 | { 60 | return InvokeReturn(Variable(variable), methodName, parameters); 61 | } 62 | 63 | public static IRightable InvokeReturn(Type dataType, string methodName, params IOperation[] parameters) 64 | { 65 | return new OperationInvokeReturn(dataType, methodName, parameters); 66 | } 67 | 68 | public static IRightable InvokeReturn( string methodName, params IOperation[] parameters) 69 | { 70 | return InvokeReturn(typeof(TData), methodName, parameters); 71 | } 72 | 73 | public static ICodeLine Invoke(IOperation variable, string methodName, params IOperation[] parameters) 74 | { 75 | return new OperationInvoke(variable, methodName, parameters); 76 | } 77 | 78 | public static ICodeLine Invoke(string variable, string methodName, params IOperation[] parameters) 79 | { 80 | return Invoke(Variable(variable), methodName, parameters); 81 | } 82 | 83 | 84 | public static ICodeLine Invoke(Type dataType, string methodName, params IOperation[] parameters) 85 | { 86 | return new OperationInvoke(dataType, methodName, parameters); 87 | } 88 | 89 | public static ICodeLine Invoke( string methodName, params IOperation[] parameters) 90 | { 91 | return Invoke(typeof(TData), methodName, parameters); 92 | } 93 | 94 | public static IRightable Get(IOperation variable, string propertyName) 95 | { 96 | return InvokeReturn(variable, "get_" + propertyName); 97 | } 98 | 99 | public static IRightable Get(string variable, string propertyName) 100 | { 101 | return Get(Variable(variable), propertyName); 102 | } 103 | 104 | public static ICodeLine Set(IOperation variable, string propertyName, IOperation value) 105 | { 106 | return Invoke(variable, "set_" + propertyName, value); 107 | } 108 | 109 | public static ICodeLine Set(string variable, string propertyName, IOperation value) 110 | { 111 | return Set(Variable(variable), propertyName, value); 112 | } 113 | 114 | public static IRightable Null() 115 | { 116 | return Constant(null); 117 | } 118 | 119 | public static IRightable Cast(IOperation variable, Type toType) 120 | { 121 | return new OperationCast(variable, toType); 122 | } 123 | 124 | public static IRightable Cast(IOperation variable) 125 | { 126 | return Cast(variable, typeof(TData)); 127 | } 128 | 129 | public static IRightable Cast(string variable, Type toType) 130 | { 131 | return Cast(Variable(variable), toType); 132 | } 133 | 134 | public static IRightable Cast(string variable) 135 | { 136 | return Cast(Variable(variable), typeof(TData)); 137 | } 138 | 139 | public static IRightable CastConst(object value, Type toType) 140 | { 141 | return Cast(Constant(value), toType); 142 | } 143 | 144 | 145 | public static IRightable CastConst(object value) 146 | { 147 | return Cast(Constant(value), typeof(TData)); 148 | } 149 | public static IRightable CreateArray(Type dataType, params IRightable[] variables) 150 | { 151 | return new OperationNewArrayInit(dataType, variables ); 152 | } 153 | 154 | public static IRightable CreateInstance(Type dataType, params IRightable[] variables) 155 | { 156 | return new OperationNew(dataType, variables); 157 | } 158 | 159 | public static IRightable CreateInstance(params IRightable[] variables) 160 | { 161 | return new OperationNew(typeof(TData), variables); 162 | } 163 | 164 | public static IRightable CreateInstance(Type dataType, IEnumerable types, params IRightable[] variables) 165 | { 166 | var generic = dataType.MakeGenericType(types.ToArray()); 167 | return CreateInstance(generic, variables); 168 | } 169 | 170 | public static IRightable CreateInstance(IEnumerable types, params IRightable[] variables) 171 | { 172 | var generic = typeof(TData).MakeGenericType(types.ToArray()); 173 | return CreateInstance(generic, variables); 174 | } 175 | 176 | 177 | public static IRightable Func(Func func, params IOperation[] parameters) 178 | { 179 | return new OperationFunc(func, parameters); 180 | } 181 | 182 | public static IRightable Func(Func func, params IOperation[] parameters) 183 | { 184 | return new OperationFunc(func, parameters); 185 | } 186 | 187 | public static ICodeLine Action(Action action, params IOperation[] parameters) 188 | { 189 | return new OperationAction(action, parameters); 190 | } 191 | 192 | public static ICodeLine Action(Action action, params IOperation[] parameters) 193 | { 194 | return new OperationAction(action, parameters); 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationCast.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | using ExpressionBuilder.Fluent; 31 | using ExpressionBuilder.Parser; 32 | using ExpressionBuilder.Utils; 33 | 34 | namespace ExpressionBuilder.Operations 35 | { 36 | public class OperationCast : IRightable 37 | { 38 | internal IOperation Variable; 39 | internal Type ToType; 40 | 41 | public OperationCast(IOperation variable, Type toType) 42 | { 43 | Variable = variable; 44 | ToType = toType; 45 | } 46 | 47 | public string ToString(ParseContext context) 48 | { 49 | return "((" + ReflectionUtil.TypeToString(ToType) + ")" + Variable.ToString(context) + ")"; 50 | } 51 | 52 | public Expression ToExpression(ParseContext context) 53 | { 54 | // var var = context.GetVariable(Variable.Name); 55 | var expr = Variable.ToExpression(context); 56 | return Expression.Convert(expr, ToType); 57 | } 58 | 59 | public void PreParseExpression(ParseContext context) 60 | { 61 | ParsedType = ToType; 62 | } 63 | 64 | public Type ParsedType { get; private set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationConst.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | using ExpressionBuilder.Fluent; 31 | using ExpressionBuilder.Parser; 32 | 33 | namespace ExpressionBuilder.Operations 34 | { 35 | public class OperationConst : IRightable 36 | { 37 | private readonly object _value; 38 | 39 | public OperationConst(object value) 40 | { 41 | _value = value; 42 | } 43 | 44 | public string ToString(ParseContext context) 45 | { 46 | if (_value == null) return "null"; 47 | var type = _value.GetType(); 48 | if (type.IsValueType || type.IsEnum) 49 | { 50 | return _value.ToString(); 51 | } 52 | return "\"" + _value + "\""; 53 | } 54 | 55 | public Expression ToExpression(ParseContext context) 56 | { 57 | return Expression.Constant(_value); 58 | } 59 | 60 | public void PreParseExpression(ParseContext context) 61 | { 62 | if (_value == null) 63 | ParsedType = typeof(object); 64 | else 65 | ParsedType = _value.GetType(); 66 | } 67 | 68 | public Type ParsedType { get; private set; } 69 | } 70 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationFunc.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Fluent; 32 | using ExpressionBuilder.Parser; 33 | using ExpressionBuilder.Utils; 34 | 35 | namespace ExpressionBuilder.Operations 36 | { 37 | public class OperationFuncBase : IRightable 38 | { 39 | protected Expression LambdaExpression; 40 | internal object Function; 41 | internal IOperation[] Parameters; 42 | protected OperationFuncBase(object func, IOperation[] parameters) 43 | { 44 | Function = func; 45 | Parameters = parameters; 46 | ParsedType = typeof(R); 47 | } 48 | 49 | public string ToString(ParseContext context) 50 | { 51 | //var functionTypes = Function.GetType().GenericTypeArguments; 52 | var dataType = ReflectionUtil.TypeToString(Function.GetType()); 53 | var result = dataType + "("; 54 | for (int i = 0; i < Parameters.Length; i++) 55 | { 56 | if (i > 0) result += ", "; 57 | result += Parameters[i].ToString(context); 58 | } 59 | result += ")"; 60 | 61 | return result; 62 | } 63 | 64 | public Expression ToExpression(ParseContext context) 65 | { 66 | var pars = new List(); 67 | foreach (var p in Parameters) 68 | { 69 | pars.Add(p.ToExpression(context)); 70 | } 71 | 72 | return Expression.Invoke(LambdaExpression, pars); 73 | } 74 | 75 | public void PreParseExpression(ParseContext context) 76 | { 77 | for (int i = 0; i < Parameters.Length; i++) 78 | { 79 | Parameters[i].PreParseExpression(context); 80 | } 81 | } 82 | 83 | public Type ParsedType { get; protected set; } 84 | } 85 | 86 | public class OperationFunc : OperationFuncBase 87 | { 88 | public OperationFunc(Func func, IOperation[] parameters) 89 | : base(func, parameters) 90 | { 91 | if (parameters.Length != 1) throw new ArgumentException(); 92 | Expression> lambda = ((p1) => func(p1)); 93 | LambdaExpression = lambda; 94 | } 95 | } 96 | 97 | public class OperationFunc : OperationFuncBase 98 | { 99 | public OperationFunc(Func func, IOperation[] parameters) 100 | : base(func, parameters) 101 | { 102 | if (parameters.Length != 2) throw new ArgumentException(); 103 | Expression> lambda = ((p1, p2) => func(p1, p2)); 104 | LambdaExpression = lambda; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationInvokeReturn.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using System.Reflection; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Parser; 34 | using ExpressionBuilder.Utils; 35 | 36 | namespace ExpressionBuilder.Operations 37 | { 38 | public class OperationInvokeReturn : IRightable 39 | { 40 | internal IOperation Variable; 41 | internal readonly Type StaticDataType; 42 | internal string MethodName; 43 | internal IOperation[] Parameters; 44 | 45 | public OperationInvokeReturn(IOperation variable, string methodName, IOperation[] parameters) 46 | { 47 | Variable = variable; 48 | MethodName = methodName; 49 | Parameters = parameters; 50 | } 51 | 52 | public OperationInvokeReturn(Type dataType, string methodName, IOperation[] parameters) 53 | { 54 | StaticDataType = dataType; 55 | MethodName = methodName; 56 | Parameters = parameters; 57 | } 58 | 59 | public string ToString(ParseContext context) 60 | { 61 | var result = string.Empty; 62 | if (StaticDataType == null) 63 | { 64 | result = Variable.ToString(context); 65 | } 66 | else 67 | { 68 | result = ReflectionUtil.TypeToString(StaticDataType); 69 | } 70 | result += "." + MethodName + "("; 71 | for (int i = 0; i < Parameters.Length; i++) 72 | { 73 | if (i > 0) result += ", "; 74 | result += Parameters[i].ToString(context); 75 | } 76 | return result + ")"; 77 | 78 | } 79 | 80 | 81 | private List _paramTypes; 82 | public void PreParseExpression(ParseContext context) 83 | { 84 | _paramTypes = new List(); 85 | for (int i = 0; i < Parameters.Length; i++) 86 | { 87 | Parameters[i].PreParseExpression(context); 88 | _paramTypes.Add(Parameters[i].ParsedType); 89 | } 90 | 91 | Type type = StaticDataType; 92 | if (StaticDataType == null) 93 | { 94 | type = Variable.ParsedType; 95 | if (Variable is OperationVariable) 96 | { 97 | var variable = context.GetVariable(((OperationVariable)Variable).Name); 98 | type = variable.DataType; 99 | } 100 | } 101 | 102 | var methodInfo = type.GetMethod( 103 | MethodName, 104 | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |BindingFlags.Static, 105 | null, 106 | _paramTypes.ToArray(), 107 | null); 108 | ParsedType = methodInfo.ReturnType; 109 | } 110 | 111 | public Type ParsedType { get; private set; } 112 | 113 | public Expression ToExpression(ParseContext context) 114 | { 115 | var pars = new List(); 116 | 117 | foreach (var param in Parameters) 118 | { 119 | pars.Add(param.ToExpression(context)); 120 | } 121 | if (_paramTypes == null) 122 | { 123 | _paramTypes = new List(); 124 | for (int i = 0; i < Parameters.Length; i++) 125 | { 126 | Parameters[i].PreParseExpression(context); 127 | _paramTypes.Add(Parameters[i].ParsedType); 128 | } 129 | } 130 | Type type = StaticDataType; 131 | if (StaticDataType == null) 132 | { 133 | type = Variable.ParsedType; 134 | if (Variable is OperationVariable) 135 | { 136 | var variable = context.GetVariable(((OperationVariable)Variable).Name); 137 | type = variable.DataType; 138 | } 139 | } 140 | 141 | var method = ReflectionUtil.GetMethod(type, MethodName, _paramTypes); 142 | 143 | if (method.GoodFrom >= 0) 144 | { 145 | var startDefault = method.GoodFrom; 146 | while (startDefault < method.ParamValues.Count) 147 | { 148 | pars.Add(Operation.Constant(method.ParamValues[method.GoodFrom]).ToExpression(context)); 149 | startDefault++; 150 | } 151 | } 152 | 153 | var my = (MethodInfo)method.Method; 154 | if ((my.Attributes & MethodAttributes.Static)==0) 155 | { 156 | return Expression.Call(Variable.ToExpression(context), method.Method as MethodInfo, pars); 157 | } 158 | return Expression.Call(method.Method as MethodInfo, pars); 159 | } 160 | } 161 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationNew.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using System.Reflection; 32 | using ExpressionBuilder.Fluent; 33 | using ExpressionBuilder.Parser; 34 | using ExpressionBuilder.Utils; 35 | 36 | namespace ExpressionBuilder.Operations 37 | { 38 | public class OperationNew : ILeftRightable 39 | { 40 | internal Type DataType; 41 | internal IRightable[] Variables; 42 | 43 | public OperationNew(Type dataType, IRightable[] variables) 44 | { 45 | DataType = dataType; 46 | Variables = variables; 47 | } 48 | 49 | public string ToString(ParseContext context) 50 | { 51 | var result = "new " + ReflectionUtil.TypeToString(DataType) + "("; 52 | for (int i = 0; i < Variables.Length; i++) 53 | { 54 | if (i > 0) result += ", "; 55 | result += Variables[i].ToString(context); 56 | } 57 | return result + ")"; 58 | } 59 | 60 | private List _constructorTypes; 61 | 62 | public void PreParseExpression(ParseContext context) 63 | { 64 | _constructorTypes = new List(); 65 | foreach (var param in Variables) 66 | { 67 | param.PreParseExpression(context); 68 | _constructorTypes.Add(param.ParsedType); 69 | } 70 | ParsedType = DataType; 71 | } 72 | 73 | public Type ParsedType { get; private set; } 74 | 75 | 76 | public Expression ToExpression(ParseContext context) 77 | { 78 | var pars = new List(); 79 | 80 | foreach (var param in Variables) 81 | { 82 | pars.Add(param.ToExpression(context)); 83 | } 84 | var constructor = ReflectionUtil.GetConstructor(DataType, _constructorTypes); 85 | if (constructor.GoodFrom >= 0) 86 | { 87 | var startDefault = constructor.GoodFrom; 88 | while (startDefault < constructor.ParamValues.Count) 89 | { 90 | pars.Add(Operation.Constant(constructor.ParamValues[constructor.GoodFrom]).ToExpression(context)); 91 | startDefault++; 92 | } 93 | } 94 | 95 | return Expression.New(constructor.Method as ConstructorInfo, pars); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationNewArrayInit.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Fluent; 32 | using ExpressionBuilder.Parser; 33 | using ExpressionBuilder.Utils; 34 | 35 | namespace ExpressionBuilder.Operations 36 | { 37 | public class OperationNewArrayInit : ILeftRightable 38 | { 39 | internal Type DataType; 40 | internal IRightable[] Variables; 41 | 42 | public OperationNewArrayInit(Type dataType, IRightable[] variables) 43 | { 44 | DataType = dataType; 45 | Variables = variables; 46 | } 47 | 48 | public string ToString(ParseContext context) 49 | { 50 | var result = "new " + ReflectionUtil.TypeToString(DataType) + "{"; 51 | for (int i = 0; i < Variables.Length; i++) 52 | { 53 | if (i > 0) result += ", "; 54 | result += Variables[i].ToString(context); 55 | } 56 | return result + "}"; 57 | } 58 | 59 | private List _constructorTypes; 60 | 61 | public void PreParseExpression(ParseContext context) 62 | { 63 | _constructorTypes = new List(); 64 | foreach (var param in Variables) 65 | { 66 | param.PreParseExpression(context); 67 | _constructorTypes.Add(param.ParsedType); 68 | } 69 | ParsedType = DataType; 70 | } 71 | 72 | public Type ParsedType { get; private set; } 73 | 74 | 75 | public Expression ToExpression(ParseContext context) 76 | { 77 | var pars = new List(); 78 | 79 | foreach (var param in Variables) 80 | { 81 | pars.Add(param.ToExpression(context)); 82 | } 83 | 84 | return Expression.NewArrayInit(DataType.GetElementType(), pars); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Operations/OperationVariable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | using ExpressionBuilder.Fluent; 31 | using ExpressionBuilder.Parser; 32 | 33 | namespace ExpressionBuilder.Operations 34 | { 35 | public class OperationVariable : ILeftRightable 36 | { 37 | internal string Name; 38 | 39 | public OperationVariable(string name) 40 | { 41 | Name = name; 42 | } 43 | 44 | public string ToString(ParseContext context) 45 | { 46 | return Name; 47 | } 48 | 49 | 50 | public void PreParseExpression(ParseContext context) 51 | { 52 | var resultVar = context.GetVariable(Name); 53 | ParsedType = resultVar.DataType; 54 | } 55 | 56 | public Type ParsedType { get; private set; } 57 | 58 | public Expression ToExpression(ParseContext context) 59 | { 60 | var variable = context.GetVariable(Name); 61 | if (variable != null) 62 | { 63 | if (variable.Expression == null) 64 | { 65 | variable.Expression = Expression.Parameter(ParsedType, Name); 66 | } 67 | return variable.Expression; 68 | } 69 | return Expression.Parameter(ParsedType, Name); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Parser/IParsable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | 31 | namespace ExpressionBuilder.Parser 32 | { 33 | public interface IParsable 34 | { 35 | string ToString(ParseContext context); 36 | Expression ToExpression(ParseContext context); 37 | void PreParseExpression(ParseContext context); 38 | Type ParsedType { get; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Parser/ParseContext.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | 32 | namespace ExpressionBuilder.Parser 33 | { 34 | public class ParseContext 35 | { 36 | public ParseContext() 37 | { 38 | _parseLevels = new List(); 39 | } 40 | 41 | internal Expression Return; 42 | private readonly List _parseLevels; 43 | internal string ReturnVariable; 44 | 45 | internal ParseLevel AddLevel() 46 | { 47 | var pl = new ParseLevel(this); 48 | _parseLevels.Add(pl); 49 | return pl; 50 | } 51 | 52 | internal int Level 53 | { 54 | get 55 | { 56 | return Count - 1; 57 | } 58 | } 59 | 60 | internal int Count 61 | { 62 | get 63 | { 64 | return _parseLevels.Count; 65 | } 66 | } 67 | 68 | internal ParseLevel Current 69 | { 70 | get 71 | { 72 | return _parseLevels[Level]; 73 | } 74 | } 75 | 76 | internal bool HasVariable(Variable var) 77 | { 78 | int i = Count - 1; 79 | while (i >= 0) 80 | { 81 | if (_parseLevels[i].HasVariable(var.Name)) 82 | { 83 | return true; 84 | } 85 | i--; 86 | } 87 | return false; 88 | } 89 | 90 | internal string Pad 91 | { 92 | get 93 | { 94 | return GetPad(Level + 1); 95 | } 96 | } 97 | 98 | internal LabelTarget ReturnLabel; 99 | 100 | internal string GetPad(int level) 101 | { 102 | var res = ""; 103 | while (level >= 0) 104 | { 105 | res += " "; 106 | level--; 107 | } 108 | return res; 109 | } 110 | 111 | internal Variable GetVariable(string name) 112 | { 113 | int i = Count - 1; 114 | while (i >= 0) 115 | { 116 | if (_parseLevels[i].HasVariable(name)) 117 | { 118 | return _parseLevels[i].GetVariable(name); 119 | } 120 | i--; 121 | } 122 | throw new Exception("Variable not found "+name); 123 | } 124 | 125 | public void RemoveLevel() 126 | { 127 | _parseLevels.RemoveAt(Level); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Parser/ParseLevel.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | 31 | namespace ExpressionBuilder.Parser 32 | { 33 | internal class ParseLevel 34 | { 35 | private readonly ParseContext _parseContext; 36 | private readonly Dictionary _variables; 37 | 38 | public ParseLevel(ParseContext parseContext) 39 | { 40 | _variables = new Dictionary(StringComparer.InvariantCultureIgnoreCase); 41 | _parseContext = parseContext; 42 | } 43 | 44 | internal void AddVariable(Variable var) 45 | { 46 | if (_parseContext.HasVariable(var)) throw new Exception("Duplicate variable"); 47 | _variables.Add(var.Name, var); 48 | } 49 | 50 | internal bool HasVariable(string name) 51 | { 52 | return _variables.ContainsKey(name); 53 | } 54 | 55 | internal Variable GetVariable(string name) 56 | { 57 | return _variables[name]; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ExpressionBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Kendar.org")] 12 | [assembly: AssemblyProduct("ExpressionBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Kendar.org 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4bbb1ae4-8a01-41c8-bf7c-4ea95f052330")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.2.0")] 36 | [assembly: AssemblyFileVersion("1.0.2.0")] 37 | 38 | [assembly: InternalsVisibleTo("FluentExpressionBuilder")] 39 | [assembly: InternalsVisibleTo("ClassBuilder")] -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/StringOperation.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using ExpressionBuilder.Fluent; 32 | 33 | namespace ExpressionBuilder 34 | { 35 | public class StringOperation 36 | { 37 | 38 | public static IRightable ToString(IOperation variable) 39 | { 40 | return Operation.InvokeReturn(variable, "ToString"); 41 | } 42 | 43 | public static IRightable ToString(string variable) 44 | { 45 | return ToString(Operation.Variable(variable)); 46 | } 47 | 48 | public static IRightable ToStringConst(object value) 49 | { 50 | return ToString(Operation.Constant(value)); 51 | } 52 | 53 | public static IRightable Compare(string lVariable, string rVariable, StringComparison comp = StringComparison.CurrentCulture) 54 | { 55 | var lValue = Operation.Variable(lVariable); 56 | var rValue = Operation.Variable(rVariable); 57 | return Compare(lValue, rValue, comp); 58 | } 59 | 60 | public static IRightable Compare(IOperation lValue, string rVariable, StringComparison comp = StringComparison.CurrentCulture) 61 | { 62 | var rValue = Operation.Variable(rVariable); 63 | return Compare(lValue, rValue, comp); 64 | } 65 | 66 | public static IRightable Compare(string lVariable, IOperation rValue, StringComparison comp = StringComparison.CurrentCulture) 67 | { 68 | var lValue = Operation.Variable(lVariable); 69 | return Compare(lValue, rValue, comp); 70 | } 71 | 72 | private static IRightable Compare(IOperation lValue, IOperation rValue, StringComparison comp) 73 | { 74 | return Operation.InvokeReturn("Compare", lValue, rValue, Operation.Constant(comp)); 75 | } 76 | 77 | public static IRightable Format(string formatString, params IOperation[] pars) 78 | { 79 | var formatPars = new List(); 80 | formatPars.Add(Operation.Constant(formatString)); 81 | formatPars.AddRange(pars); 82 | 83 | return Operation.InvokeReturn("Format", formatPars.ToArray()); 84 | } 85 | 86 | public static IRightable Length(IOperation variable) 87 | { 88 | return Operation.InvokeReturn(variable, "Length"); 89 | } 90 | 91 | public static IRightable Length(string variable) 92 | { 93 | return ToString(Operation.Variable(variable)); 94 | } 95 | 96 | public static IRightable Length(object value) 97 | { 98 | return ToString(Operation.Constant(value)); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/TODO.txt: -------------------------------------------------------------------------------- 1 | * Add For 2 | * Create the parser 3 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Utils/ExpressionUtil.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using System.Linq.Expressions; 32 | using System.Reflection; 33 | using ExpressionBuilder.Enums; 34 | 35 | namespace ExpressionBuilder.Utils 36 | { 37 | public class ExpressionUtil 38 | { 39 | /* public static string GetDebugView(Expression ex) 40 | { 41 | var property = ex.GetType().GetProperty("DebugView", BindingFlags.Instance | BindingFlags.NonPublic); 42 | return (string)property.GetGetMethod(true).Invoke(ex, new object[] {}); 43 | }*/ 44 | public static List GetPropertyInfos(Expression> propertyLambda) 45 | { 46 | var result = new List(); 47 | Type type = typeof(TSource); 48 | 49 | var member = propertyLambda.Body as MemberExpression; 50 | 51 | // Check if there is a cast to object in first position 52 | if (member == null) 53 | { 54 | var unary = propertyLambda.Body as UnaryExpression; 55 | if (unary != null) 56 | { 57 | member = unary.Operand as MemberExpression; 58 | } 59 | } 60 | 61 | // Second<-First<-a 62 | while (member != null) 63 | { 64 | var propInfo = member.Member as PropertyInfo; 65 | if (propInfo == null) 66 | throw new ArgumentException(string.Format( 67 | "Expression '{0}' refers to a field, not a property.", 68 | propertyLambda.ToString())); 69 | 70 | result.Add(new LambdaPropertyDescriptor 71 | { 72 | DataType = propInfo.PropertyType, 73 | Name = propInfo.Name, 74 | Property = propInfo 75 | }); 76 | member = member.Expression as MemberExpression; 77 | } 78 | result.Reverse(); 79 | return result; 80 | } 81 | 82 | public static Func GetComparer(Expression> propertyLambda, 83 | ComparaisonOperator oper = ComparaisonOperator.Equal) 84 | { 85 | var returnType = GetPropertyInfos(propertyLambda).Last().DataType; 86 | Func realLambda = propertyLambda.Compile(); 87 | 88 | return Function.Create() 89 | .WithParameter("source") 90 | .WithParameter("toCompare") 91 | .WithBody( 92 | CodeLine.CreateVariable(returnType, "toCompareCast"), 93 | CodeLine.CreateVariable("returnVariable"), 94 | CodeLine.Assign("toCompareCast", Operation.Cast("toCompare", returnType)), 95 | 96 | CodeLine.Assign("returnVariable", 97 | Condition.Compare("toCompareCast", 98 | Operation.Cast( 99 | Operation.Func(realLambda, Operation.Variable("source")), 100 | returnType), oper)) 101 | ) 102 | .Returns("returnVariable") 103 | .ToLambda>(); 104 | } 105 | 106 | public static PropertyGetSet GetGetterAndSetter(Expression> propertyLambda) 107 | { 108 | var getSetter = new PropertyGetSet(); 109 | getSetter.Getter = BuildGetter(propertyLambda); 110 | getSetter.Setter = BuildSetter(propertyLambda); 111 | return getSetter; 112 | } 113 | 114 | private static Action BuildSetter(Expression> propertyLambda) 115 | { 116 | throw new NotImplementedException(); 117 | } 118 | 119 | private static Func BuildGetter(Expression> propertyLambda) 120 | { 121 | throw new NotImplementedException(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Utils/LambdaPropertyDescriptor.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Reflection; 30 | 31 | namespace ExpressionBuilder.Utils 32 | { 33 | public class LambdaPropertyDescriptor 34 | { 35 | public string Name { get; set; } 36 | public Type DataType { get; set; } 37 | public PropertyInfo Property { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Utils/MethodCallDescriptor.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Reflection; 31 | 32 | namespace ExpressionBuilder.Utils 33 | { 34 | public class MethodCallDescriptor 35 | { 36 | public MethodCallDescriptor() 37 | { 38 | ParamTypes = new List(); 39 | ParamValues = new List(); 40 | GoodFrom = 0; 41 | } 42 | 43 | public MethodBase Method { get; set; } 44 | public List ParamTypes { get; set; } 45 | public List ParamValues { get; set; } 46 | public int GoodFrom { get; set; } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Utils/PropertyGetSet.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | 30 | namespace ExpressionBuilder.Utils 31 | { 32 | public class PropertyGetSet 33 | { 34 | public Func Getter; 35 | public Action Setter; 36 | } 37 | } -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Utils/ReflectionUtil.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using System.Reflection; 32 | 33 | namespace ExpressionBuilder.Utils 34 | { 35 | public static class ReflectionUtil 36 | { 37 | const BindingFlags PUBLIC_STATIC_INST = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance; 38 | const BindingFlags ALL_STATIC_INST = PUBLIC_STATIC_INST | BindingFlags.NonPublic; 39 | public static string TypeToString(Type type) 40 | { 41 | var typeName = type.Name; 42 | var thinghy = typeName.IndexOf('`'); 43 | if (thinghy > 0) 44 | { 45 | typeName = typeName.Substring(0, thinghy); 46 | } 47 | var res = type.Namespace + "." + typeName; 48 | if (type.IsGenericType) 49 | { 50 | res += "<"; 51 | var args = type.GetGenericArguments(); 52 | for (int i = 0; i < args.Length; i++) 53 | { 54 | if (i > 0) res += ", "; 55 | res += TypeToString(args[i]); 56 | } 57 | res += ">"; 58 | } 59 | return res; 60 | } 61 | 62 | public static IEnumerable GetMethods(Type type) 63 | { 64 | var methods = 65 | type.GetMethods(ALL_STATIC_INST); 66 | foreach (var method in methods) 67 | { 68 | if (method.Name.StartsWith("get_") || method.Name.StartsWith("set_")) continue; 69 | var result = EvaluateCorrectness(method.GetParameters(), method.GetParameters().Select((a)=>a.ParameterType).ToList()); 70 | if (result != null) 71 | { 72 | result.Method = method; 73 | yield return result; 74 | } 75 | } 76 | } 77 | 78 | public static MethodCallDescriptor GetMethod(Type type, string methodName, List paramTypes) 79 | { 80 | var methods = type.GetMethods(ALL_STATIC_INST).Where(a => 81 | string.Compare(methodName, a.Name, StringComparison.InvariantCultureIgnoreCase) == 0); 82 | if (paramTypes == null) 83 | { 84 | paramTypes = new List(); 85 | } 86 | foreach (var method in methods) 87 | { 88 | 89 | var result = EvaluateCorrectness(method.GetParameters(), paramTypes); 90 | if (result != null) 91 | { 92 | result.Method = method; 93 | return result; 94 | } 95 | } 96 | throw new MissingMethodException(); 97 | } 98 | 99 | public static MethodCallDescriptor GetConstructor(Type type, List paramTypes) 100 | { 101 | var methods = type.GetConstructors(); 102 | foreach (var method in methods) 103 | { 104 | var result = EvaluateCorrectness(method.GetParameters(), paramTypes); 105 | if (result != null) 106 | { 107 | result.Method = method; 108 | return result; 109 | } 110 | } 111 | throw new MissingMethodException(); 112 | } 113 | 114 | private static MethodCallDescriptor EvaluateCorrectness(ParameterInfo[] mp, List paramTypes) 115 | { 116 | var result = new MethodCallDescriptor(); 117 | if (mp.Length < paramTypes.Count) return null; 118 | int i; 119 | for (i = 0; i < paramTypes.Count; i++) 120 | { 121 | var methodType = mp[i].ParameterType; 122 | var paramType = paramTypes[i]; 123 | if (!paramType.IsSubclassOf(methodType) && paramType != methodType) 124 | { 125 | return null; 126 | } 127 | result.ParamTypes.Add(methodType); 128 | result.ParamValues.Add(null); 129 | result.GoodFrom = i + 1; 130 | } 131 | if (mp.Length != paramTypes.Count) 132 | { 133 | for (int j = result.GoodFrom; j < mp.Length; j++) 134 | { 135 | var methodParameter = mp[j]; 136 | if (!methodParameter.IsOptional) return null; 137 | result.ParamTypes.Add(methodParameter.ParameterType); 138 | result.ParamValues.Add(methodParameter.DefaultValue); 139 | } 140 | } 141 | return result; 142 | } 143 | 144 | 145 | public static PropertyInfo[] GetPublicProperties(Type type) 146 | { 147 | if (type.IsInterface) 148 | { 149 | var propertyInfos = new List(); 150 | 151 | var considered = new List(); 152 | var queue = new Queue(); 153 | considered.Add(type); 154 | queue.Enqueue(type); 155 | while (queue.Count > 0) 156 | { 157 | var subType = queue.Dequeue(); 158 | foreach (var subInterface in subType.GetInterfaces()) 159 | { 160 | if (considered.Contains(subInterface)) continue; 161 | 162 | considered.Add(subInterface); 163 | queue.Enqueue(subInterface); 164 | } 165 | 166 | var typeProperties = subType.GetProperties(ALL_STATIC_INST); 167 | 168 | var newPropertyInfos = typeProperties 169 | .Where(x => !propertyInfos.Contains(x)); 170 | 171 | propertyInfos.InsertRange(0, newPropertyInfos); 172 | } 173 | 174 | return propertyInfos.ToArray(); 175 | } 176 | 177 | return type.GetProperties(ALL_STATIC_INST); 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/Variable.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | 31 | namespace ExpressionBuilder 32 | { 33 | public class Variable 34 | { 35 | internal Type DataType; 36 | internal string Name; 37 | internal bool Assignable; 38 | internal Expression Expression; 39 | 40 | public Variable(Type dataType, string name, bool assignable = true) 41 | { 42 | DataType = dataType; 43 | Name = name; 44 | Assignable = assignable; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ExpressionBuilder/ExpressionBuilder/While.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Linq.Expressions; 31 | using ExpressionBuilder.Fluent; 32 | using ExpressionBuilder.Parser; 33 | using ExpressionBuilder.CodeLines; 34 | 35 | namespace ExpressionBuilder 36 | { 37 | public class While : IWhile, ICodeLine 38 | { 39 | internal List CodeLines; 40 | internal Condition Condition; 41 | 42 | internal While(Condition condition) 43 | { 44 | if (condition == null) throw new ArgumentException(); 45 | Condition = condition; 46 | CodeLines = new List(); 47 | } 48 | 49 | public ICodeLine Do(ICodeLine firstCodeLine, params ICodeLine[] codeLines) 50 | { 51 | CodeLines.Add(firstCodeLine); 52 | foreach (var codeLine in codeLines) 53 | { 54 | CodeLines.Add(codeLine); 55 | } 56 | return this; 57 | } 58 | 59 | 60 | public string ToString(ParseContext context) 61 | { 62 | var result = "while(" + Condition.ToString(context) + ")\n"; 63 | result += context.Pad + "{\n"; 64 | context.AddLevel(); 65 | 66 | foreach (var line in CodeLines) 67 | { 68 | var createVariable = line as CreateVariable; 69 | if (createVariable != null) 70 | { 71 | createVariable.DefaultInitialize(context); 72 | } 73 | result += context.Pad + line.ToString(context) + ";\n"; 74 | } 75 | 76 | context.RemoveLevel(); 77 | result += context.Pad + "}"; 78 | return result; 79 | } 80 | 81 | public void PreParseExpression(ParseContext context) 82 | { 83 | //var pl = context.Current; 84 | Condition.PreParseExpression(context); 85 | context.AddLevel(); 86 | 87 | foreach (var line in CodeLines) 88 | { 89 | line.PreParseExpression(context); 90 | } 91 | 92 | context.RemoveLevel(); 93 | } 94 | 95 | public Type ParsedType { get; private set; } 96 | 97 | public Expression ToExpression(ParseContext context) 98 | { 99 | var conditionExpression = Condition.ToExpression(context); 100 | context.AddLevel(); 101 | 102 | var thenLine = new List(); 103 | var listOfThenVars = new List(); 104 | foreach (var line in CodeLines) 105 | { 106 | var expLine = line.ToExpression(context); 107 | 108 | var createVariable = line as CreateVariable; 109 | if (createVariable != null) 110 | { 111 | listOfThenVars.Add((ParameterExpression)expLine); 112 | expLine = createVariable.DefaultInitialize(context); 113 | } 114 | thenLine.Add(expLine); 115 | } 116 | var thenBlock = Expression.Block(listOfThenVars.ToArray(), thenLine); 117 | 118 | context.RemoveLevel(); 119 | 120 | LabelTarget label = Expression.Label(Guid.NewGuid().ToString()); 121 | var ifThenElse = Expression.IfThenElse( 122 | conditionExpression, 123 | thenBlock, 124 | Expression.Break(label)); 125 | return Expression.Loop(ifThenElse, label); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/BuildCleaner.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/build_utils/BuildCleaner.exe -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/CommentsHeader.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/build_utils/CommentsHeader.exe -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/GenericHelpers.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/build_utils/GenericHelpers.dll -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/Ionic.Zip.Reduced.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/build_utils/Ionic.Zip.Reduced.dll -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/README.md: -------------------------------------------------------------------------------- 1 | ## Setup 2 | 3 | * Rename "dobuild_env.template" into "dobuild_env.bat" 4 | * Set the VS_VERSION variable to the correct Visual Studio version 5 | * Visual Studio 2010: 10.0 6 | * Visual Studio 2012: 11.0 7 | * Visual Studio 2013: 12.0 8 | 9 | ## Usage 10 | 11 | The various utilities are: 12 | 13 | * dobuild.bat: Build all projects and generate all the nuget packages under "tmp_nuget" directory 14 | * zipproject.bat: Zip the project into ..\..\[ProjectName].[YYYYmmdd].[hhss].zip without bin, obj, nuget packages, test results 15 | * zipproject.nuget.bat: As zipproject.bat but including the nuget packages directory 16 | * setcopyright.bat: Set the copyright on the solution .cs files. The copyright notice is in the license.cs file 17 | 18 | ## Debugging 19 | 20 | While debugging, all files will be kept! No cleanup will be made! 21 | 22 | To debug the whole build process the variable VERBOSITY can be set to TRUE (mind the capital letters!) in dobuild_env.bat 23 | 24 | To debug single parts of the build the single line in dobuild.bat can be surrounded like this 25 | 26 | ... 27 | SET VERBOSITY=TRUE 28 | call dobuild_single ConcurrencyHelpers 4.0 net40 src\ConcurrencyHelpers 29 | SET VERBOSITY=FALSE 30 | ... 31 | 32 | At this point only the build of ConcurrencyHelpers with framework 4.0 will be shown as verbose 33 | 34 | ## Extra files 35 | 36 | * license.cs: The copyright notice to prepend on all .cs files 37 | * dobuild_env.bat: The Visual Studio environment variables 38 | * dobuild_*.bat: Utilities to build the project (not intented for direct usage) 39 | * VisualStudioIdentifier.exe: Utility to find the location of devenv.exe 40 | * BuildCleaner.exe: Utility to find the solution files and zip them 41 | * CommentsHeader.exe: Utility to find add comments on all files -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/VisualStudioIdentifier.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kendarorg/ExpressionBuilder/b9dc4731934715cba4e217b56634c7ff6f8066a4/ExpressionBuilder/build_utils/VisualStudioIdentifier.exe -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | call dobuild_env.bat 3 | 4 | call dobuild_single ExpressionBuilder 4.0 net40 5 | call dobuild_single ExpressionBuilder 4.5 net45 6 | call dobuild_nuget ExpressionBuilder 7 | 8 | call dobuild_clean 9 | pause 10 | -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild_clean.bat: -------------------------------------------------------------------------------- 1 | @echo off >NUL 2>NUL 2 | 3 | if "%VS_VERSION%"=="" ( 4 | echo ERROR!!! 5 | echo This batch cannot be run alone!! 6 | pause 7 | exit 1 8 | ) 9 | 10 | echo Cleanup 11 | echo ================================================================ 12 | echo * Cleanup started 13 | call cleanup 14 | del /q cleanup.bat >NUL 2>NUL 15 | echo * Cleanup completed 16 | echo. -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild_env.bat: -------------------------------------------------------------------------------- 1 | @echo off >NUL 2>NUL 2 | 3 | SET VS_VERSION=14.0 4 | SET VERBOSITY=FALSE 5 | 6 | echo Setting up environment variables 7 | echo ================================================================ 8 | 9 | SET UTILS_ROOT=%CD% 10 | 11 | SET VS_NAME=VSPATH 12 | 13 | VisualStudioIdentifier %VS_VERSION% %VS_NAME% vs.bat" 14 | 15 | pause 16 | call vs.bat 17 | if "%VERBOSITY%"=="TRUE" ( 18 | del /q vs.bat 19 | ) ELSE ( 20 | del /q vs.bat >NUL 2>NUL 21 | ) 22 | Cd .. 23 | SET CURRENT_DIR=%CD% 24 | SET SOLUTION_DIR=%CD% 25 | SET NUGET_DIR=%CURRENT_DIR%\.nuget 26 | 27 | 28 | cd %VSPATH% 29 | cd.. 30 | SET VSPATH=%CD% 31 | CD %CURRENT_DIR% 32 | 33 | call "%VSPATH%\Tools\VsDevCmd.bat" 34 | 35 | 36 | echo @echo off ^>NUL 2^>NUL > %UTILS_ROOT%\cleanup.bat 37 | 38 | REM mkdir tmp_nuget 39 | CD %UTILS_ROOT% 40 | echo. -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild_env.template: -------------------------------------------------------------------------------- 1 | @echo off >NUL 2>NUL 2 | 3 | SET VS_VERSION=12.0 4 | SET VERBOSITY=FALSE 5 | 6 | echo Setting up environment variables 7 | echo ================================================================ 8 | 9 | SET UTILS_ROOT=%CD% 10 | 11 | SET VS_NAME=VSPATH 12 | 13 | VisualStudioIdentifier %VS_VERSION% %VS_NAME% vs.bat" 14 | call vs.bat 15 | if "%VERBOSITY%"=="TRUE" ( 16 | del /q vs.bat 17 | ) ELSE ( 18 | del /q vs.bat >NUL 2>NUL 19 | ) 20 | Cd .. 21 | SET CURRENT_DIR=%CD% 22 | SET SOLUTION_DIR=%CD% 23 | SET NUGET_DIR=%CURRENT_DIR%\.nuget 24 | 25 | 26 | cd %VSPATH% 27 | cd.. 28 | SET VSPATH=%CD% 29 | CD %CURRENT_DIR% 30 | 31 | call "%VSPATH%\Tools\VsDevCmd.bat" 32 | 33 | echo @echo off ^>NUL 2^>NUL > cleanup.bat 34 | 35 | REM mkdir tmp_nuget 36 | CD %UTILS_ROOT% 37 | echo. -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild_nuget.bat: -------------------------------------------------------------------------------- 1 | @echo off >NUL 2>NUL 2 | 3 | if "%VS_VERSION%"=="" ( 4 | echo ERROR!!! 5 | echo This batch cannot be run alone!! 6 | pause 7 | exit 1 8 | ) 9 | 10 | SET PROJECT_NAME=%1 11 | SET PROJECT_DIR=%SOLUTION_DIR%\%1 12 | if "%2"=="" (SET PROJECT_DIR=%SOLUTION_DIR%\%1) ELSE (SET PROJECT_DIR=%SOLUTION_DIR%\%2) 13 | 14 | echo Building nuget package for: %1 15 | echo ================================================================ 16 | 17 | SET NUGET_VERBOSITY=quiet 18 | if "%VERBOSITY%"=="TRUE" (SET NUGET_VERBOSITY=detailed) ELSE (SET NUGET_VERBOSITY=quiet) 19 | 20 | "%NUGET_DIR%\NuGet.exe" pack "%PROJECT_DIR%\%PROJECT_NAME%.nuspec" -Verbosity %NUGET_VERBOSITY% -basepath "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%" -OutputDirectory "%SOLUTION_DIR%\tmp_nuget" 21 | 22 | echo if "%VERBOSITY%"=="TRUE" ( >>cleanup.bat 23 | echo echo * NOT Cleaning up temporary nuget for %PROJECT_NAME% >>cleanup.bat 24 | echo ) else ( >>cleanup.bat 25 | echo rd /q /s "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%" ^>NUL 2^>NUL >>cleanup.bat 26 | echo ) >>cleanup.bat 27 | 28 | echo * Nuget package created 29 | echo. -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild_simple.bat: -------------------------------------------------------------------------------- 1 | @echo off >NUL 2>NUL 2 | 3 | if "%VS_VERSION%"=="" ( 4 | echo ERROR!!! 5 | echo This batch cannot be run alone!! 6 | pause 7 | exit 1 8 | ) 9 | 10 | SET PROJECT_NAME=%1 11 | SET FRAMEWORK_VERSION=%2 12 | SET FRAMEWORK_NUGET_VERSION=%3 13 | SET PROJECT_DIR=%SOLUTION_DIR%\%1 14 | 15 | echo Building: %1/.NET %2 with nuget 16 | echo ================================================================ 17 | 18 | if "%4"=="" (SET PROJECT_DIR=%SOLUTION_DIR%\%1) ELSE (SET PROJECT_DIR=%SOLUTION_DIR%\%4) 19 | 20 | if "%VERBOSITY%"=="TRUE" ( 21 | echo * Cleaning up build directories for %PROJECT_NAME%... 22 | rd /s /q "%PROJECT_DIR%\obj" 23 | rd /s /q "%PROJECT_DIR%\bin" 24 | ) else ( 25 | echo * Cleaning up build directories for %PROJECT_NAME%... 26 | rd /s /q "%PROJECT_DIR%\obj" >NUL 2>NUL 27 | rd /s /q "%PROJECT_DIR%\bin" >NUL 2>NUL 28 | ) 29 | 30 | echo if "%VERBOSITY%"=="TRUE" ( >>cleanup.bat 31 | echo echo * Not Cleaning up build directories for %PROJECT_NAME%/.Net %FRAMEWORK_VERSION%... >>cleanup.bat 32 | echo ) else ( >>cleanup.bat 33 | echo rd /s /q "%PROJECT_DIR%\obj" ^>NUL 2^>NUL >>cleanup.bat 34 | echo rd /s /q "%PROJECT_DIR%\bin" ^>NUL 2^>NUL >>cleanup.bat 35 | echo ) >>cleanup.bat 36 | 37 | echo * Compiling... 38 | 39 | 40 | if "%VERBOSITY%"=="TRUE" ( 41 | msbuild %PROJECT_DIR%/%PROJECT_NAME%.csproj /verbosity:n /p:TargetFrameworkVersion=v%FRAMEWORK_VERSION%;Configuration=Release;Platform=AnyCPU /p:DefineConstants=%FRAMEWORK_NUGET_VERSION% 42 | ) ELSE ( 43 | msbuild %PROJECT_DIR%/%PROJECT_NAME%.csproj /verbosity:q /p:TargetFrameworkVersion=v%FRAMEWORK_VERSION%;Configuration=Release;Platform=AnyCPU /p:DefineConstants=%FRAMEWORK_NUGET_VERSION% >NUL 2>NUL 44 | ) 45 | 46 | echo * Compilation completed 47 | echo. -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/dobuild_single.bat: -------------------------------------------------------------------------------- 1 | @echo off >NUL 2>NUL 2 | 3 | if "%VS_VERSION%"=="" ( 4 | echo ERROR!!! 5 | echo This batch cannot be run alone!! 6 | pause 7 | exit 1 8 | ) 9 | 10 | SET PROJECT_NAME=%1 11 | SET FRAMEWORK_VERSION=%2 12 | SET FRAMEWORK_NUGET_VERSION=%3 13 | SET PROJECT_DIR=%SOLUTION_DIR%\%1 14 | 15 | echo Building: %1/.NET %2 with nuget 16 | echo ================================================================ 17 | 18 | if "%4"=="" (SET PROJECT_DIR=%SOLUTION_DIR%\%1) ELSE (SET PROJECT_DIR=%SOLUTION_DIR%\%4) 19 | 20 | echo * Creating nuget target dirs... 21 | 22 | if "%VERBOSITY%"=="TRUE" ( 23 | mkdir %SOLUTION_DIR%\tmp_nuget 24 | mkdir %SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME% 25 | mkdir %SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin 26 | mkdir %SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION% 27 | ) ELSE ( 28 | mkdir %SOLUTION_DIR%\tmp_nuget >NUL 2>NUL 29 | mkdir %SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME% >NUL 2>NUL 30 | mkdir %SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin >NUL 2>NUL 31 | mkdir %SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION% >NUL 2>NUL 32 | ) 33 | 34 | 35 | if "%VERBOSITY%"=="TRUE" ( 36 | echo * Cleaning up build directories... 37 | rd /s /q "%PROJECT_DIR%\obj" 38 | rd /s /q "%PROJECT_DIR%\bin" 39 | ) else ( 40 | echo * Cleaning up build directories... 41 | rd /s /q "%PROJECT_DIR%\obj" >NUL 2>NUL 42 | rd /s /q "%PROJECT_DIR%\bin" >NUL 2>NUL 43 | ) 44 | 45 | echo if "%VERBOSITY%"=="TRUE" ( >>cleanup.bat 46 | echo echo * NOT Cleaning up build directories for %PROJECT_NAME%/.Net %FRAMEWORK_VERSION%... >>cleanup.bat 47 | echo ) else ( >>cleanup.bat 48 | echo rd /s /q "%PROJECT_DIR%\obj" ^>NUL 2^>NUL >>cleanup.bat 49 | echo rd /s /q "%PROJECT_DIR%\bin" ^>NUL 2^>NUL >>cleanup.bat 50 | echo ) >>cleanup.bat 51 | 52 | echo * Compiling... 53 | 54 | 55 | if "%VERBOSITY%"=="TRUE" ( 56 | msbuild %PROJECT_DIR%/%PROJECT_NAME%.csproj /verbosity:n /p:TargetFrameworkVersion=v%FRAMEWORK_VERSION%;Configuration=Release;Platform=AnyCPU /p:DefineConstants=%FRAMEWORK_NUGET_VERSION% 57 | ) ELSE ( 58 | msbuild %PROJECT_DIR%/%PROJECT_NAME%.csproj /verbosity:q /p:TargetFrameworkVersion=v%FRAMEWORK_VERSION%;Configuration=Release;Platform=AnyCPU /p:DefineConstants=%FRAMEWORK_NUGET_VERSION% >NUL 2>NUL 59 | ) 60 | 61 | echo * Copying data on tmp_nuget... 62 | 63 | if "%VERBOSITY%"=="TRUE" ( 64 | copy /Y %PROJECT_DIR%\bin\Release\*.dll "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" 65 | copy /Y %PROJECT_DIR%\bin\Release\*.exe "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" 66 | copy /Y %PROJECT_DIR%\bin\Release\*.config "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" 67 | copy /Y %PROJECT_DIR%\bin\Release\*.txt "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" 68 | copy /Y %PROJECT_DIR%\bin\Release\*.md "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" 69 | ) ELSE ( 70 | copy /Y %PROJECT_DIR%\bin\Release\*.dll "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" >NUL 2>NUL 71 | copy /Y %PROJECT_DIR%\bin\Release\*.exe "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" >NUL 2>NUL 72 | copy /Y %PROJECT_DIR%\bin\Release\*.config "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" >NUL 2>NUL 73 | copy /Y %PROJECT_DIR%\bin\Release\*.txt "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" >NUL 2>NUL 74 | copy /Y %PROJECT_DIR%\bin\Release\*.md "%SOLUTION_DIR%\tmp_nuget\%PROJECT_NAME%\bin\%FRAMEWORK_NUGET_VERSION%" >NUL 2>NUL 75 | ) 76 | 77 | echo * Compilation completed 78 | echo. -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/license.cs: -------------------------------------------------------------------------------- 1 | // =========================================================== 2 | // Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // * Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | // =========================================================== 26 | 27 | -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/setcopyright.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Setting copyright on solution 4 | echo ================================================================ 5 | SET UTILS_ROOT=%CD% 6 | cd .. 7 | call "%UTILS_ROOT%\CommentsHeader" -e cs -t "%UTILS_ROOT%\license.cs" 8 | echo * Copyright set 9 | echo. 10 | pause -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/zipproject.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Zipping solution 3 | echo ================================================================ 4 | echo. 5 | SET UTILS_ROOT=%CD% 6 | cd .. 7 | %UTILS_ROOT%\BuildCleaner -dp _ReSharper*.* -ip bin;obj;.git;packages;.nuget;TestResults; -z 8 | echo. 9 | echo * Solution zipped without nuget packages 10 | echo. 11 | pause -------------------------------------------------------------------------------- /ExpressionBuilder/build_utils/ziproject.nuget.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Zipping solution 3 | echo ================================================================ 4 | echo. 5 | SET UTILS_ROOT=%CD% 6 | cd .. 7 | %UTILS_ROOT%\BuildCleaner -dp _ReSharper*.* -ip bin;obj;.git;TestResults -z 8 | echo. 9 | echo * Solution zipped with nuget packages 10 | echo. 11 | pause -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, Enrico Da Ros/kendar.org 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | --------------------------------------------------------------------------------