Local 4 years ago
parent
commit
42b5cf02b9

+ 16 - 0
DrasticTemplateEngine/Class1.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DrasticTemplateEngine
+{
+    public class DteRunner
+    {
+        public DteRunner()
+        {
+            
+        }
+    }
+}

+ 54 - 0
DrasticTemplateEngine/DrasticTemplateEngine.csproj

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>a043ad4d-3ef9-4b8c-b90b-64f3b44eaae6</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DrasticTemplateEngine</RootNamespace>
+    <AssemblyName>DrasticTemplateEngine</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System"/>
+    
+    <Reference Include="System.Core"/>
+    <Reference Include="System.Xml.Linq"/>
+    <Reference Include="System.Data.DataSetExtensions"/>
+    
+    
+    <Reference Include="Microsoft.CSharp"/>
+    
+    <Reference Include="System.Data"/>
+    
+    <Reference Include="System.Net.Http"/>
+    
+    <Reference Include="System.Xml"/>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Class1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ </Project>

+ 36 - 0
DrasticTemplateEngine/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("DrasticTemplateEngine")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DrasticTemplateEngine")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("a043ad4d-3ef9-4b8c-b90b-64f3b44eaae6")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 2 - 2
FormulaEnginePoC/CSharpProvider/CodeCompiler.cs

@@ -40,9 +40,9 @@ namespace FormulaEnginePoC.CSharpProvider
             if (_compilerResults.Errors.HasErrors)
             {
                 var sb = new StringBuilder();
-                foreach (var item in _compilerResults.Errors)
+                foreach (CompilerError item in _compilerResults.Errors)
                 {
-                    sb.AppendLine(item.ToString());
+                    sb.AppendLine($"{item.ErrorText}({item.ErrorNumber})");
                 }
 
                 throw new ArgumentException("Compile fail:" + sb);

+ 0 - 1
FormulaEnginePoC/FormulaEngine/ExpressionTokenSplitter.cs

@@ -17,7 +17,6 @@ namespace FormulaEnginePoC.FormulaEngine
 
         public enum TokenId
         {
-            // ReSharper disable once UnusedMember.Global
             Unknown,
 
             End,

+ 8 - 7
FormulaEnginePoC/FormulaEngine/FormulaConverter.cs

@@ -81,11 +81,11 @@ namespace FormulaEnginePoC.FormulaEngine
             };
         }
 
-        public static string Convert(string friendInput, TypeMapping mapping, FormulaValueTypeConvert valueConvert = FormulaValueTypeConvert.ConvertToDouble)
+        public static string Convert(string friendInput, TypeMapping mapping, FormulaValueTypeConversion valueConversion = FormulaValueTypeConversion.ConvertToDouble)
         {
             var functions = new Dictionary<string, string>(Functions);
 
-            if (valueConvert == FormulaValueTypeConvert.ConvertToDecimal)
+            if (valueConversion == FormulaValueTypeConversion.ConvertToDecimal)
             {
                 functions["NUM"] = $"{nameof(MoreFunction)}.{nameof(MoreFunction.ToDecimal)}";
             }
@@ -111,12 +111,13 @@ namespace FormulaEnginePoC.FormulaEngine
                     }
                     else if (mapping.TryGetProperty(token.Text, out var property))
                     {
-                        if (property.DataType == typeof(decimal) && valueConvert == FormulaValueTypeConvert.ConvertToDouble)
+                        if (valueConversion == FormulaValueTypeConversion.ConvertToDouble && property.DataType == typeof(decimal))
+                        {
+                            code.Append($"{numFunction} ( p.{property.Name} )");
+                        }
+                        else if (valueConversion == FormulaValueTypeConversion.ConvertToDecimal && (property.DataType == typeof(float) || property.DataType == typeof(double)))
                         {
-                            //值类型转换
-
                             code.Append($"{numFunction} ( p.{property.Name} )");
-
                         }
                         else
                         {
@@ -131,7 +132,7 @@ namespace FormulaEnginePoC.FormulaEngine
                 else
                 {
                     //值类型转换
-                    if (token.Id == ExpressionTokenSplitter.TokenId.RealLiteral && valueConvert == FormulaValueTypeConvert.ConvertToDouble)
+                    if (token.Id == ExpressionTokenSplitter.TokenId.RealLiteral)
                     {
                         code.Append($"{numFunction} ( {token.Text} )");
                     }

+ 1 - 1
FormulaEnginePoC/FormulaEngine/Convert.cs

@@ -5,7 +5,7 @@ using System.Text;
 
 namespace FormulaEnginePoC.FormulaEngine
 {
-    public enum FormulaValueTypeConvert
+    public enum FormulaValueTypeConversion
     {
         ConvertToDouble = 1,
         ConvertToDecimal = 2,

+ 2 - 2
FormulaEnginePoC/FormulaEnginePoC.csproj

@@ -20,7 +20,7 @@
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
     <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DefineConstants>TRACE;DEBUG</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
@@ -68,7 +68,7 @@
     <Compile Include="DynamicExpressionParse\Signature.cs" />
     <Compile Include="DynamicExpressionParse\FormulaCompiler.cs" />
     <Compile Include="FormulaEngine\FormulaConverter.cs" />
-    <Compile Include="FormulaEngine\Convert.cs" />
+    <Compile Include="FormulaEngine\FormulaValueTypeConversion.cs" />
     <Compile Include="FormulaEngine\Mapping\PropertyMapping.cs" />
     <Compile Include="FormulaEngine\Mapping\TypeMapping.cs" />
     <Compile Include="FormulaEngine\MoreFunction.cs" />

+ 6 - 0
PoC.sln

@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "@", "@", "{65C086E5-79F9-46
 		README.md = README.md
 	EndProjectSection
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrasticTemplateEngine", "DrasticTemplateEngine\DrasticTemplateEngine.csproj", "{A043AD4D-3EF9-4B8C-B90B-64F3B44EAAE6}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -32,6 +34,10 @@ Global
 		{0580C2E7-AA6E-451F-AEE0-9AF30B244A75}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{0580C2E7-AA6E-451F-AEE0-9AF30B244A75}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{0580C2E7-AA6E-451F-AEE0-9AF30B244A75}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A043AD4D-3EF9-4B8C-B90B-64F3B44EAAE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A043AD4D-3EF9-4B8C-B90B-64F3B44EAAE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A043AD4D-3EF9-4B8C-B90B-64F3B44EAAE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A043AD4D-3EF9-4B8C-B90B-64F3B44EAAE6}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE