Skip to content

Commit f876a35

Browse files
committed
1.1.10版本,修改部分方法
1 parent fe62005 commit f876a35

File tree

5 files changed

+165
-8
lines changed

5 files changed

+165
-8
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ToolGood.Algorithm
22
===================
3+
ToolGood.Algorithm支持`四则运算``Excel函数`,并支持`自定义参数`
34

45
## 快速上手
56
``` csharp
@@ -10,9 +11,42 @@ ToolGood.Algorithm
1011
}
1112
var c = engine.TryEvaluate("2+3", 0);
1213
```
14+
## 自定义参数
15+
``` csharp
16+
//定义圆柱信息
17+
public class Cylinder : AlgorithmEngine
18+
{
19+
private int _radius;
20+
private int _height;
21+
public Cylinder(int radius, int height)
22+
{
23+
_radius = radius;
24+
_height = height;
25+
}
26+
27+
protected override Operand GetParameter(Operand curOpd)
28+
{
29+
if (curOpd.Parameter == "[半径]") {
30+
return new Operand(OperandType.NUMBER, _radius);
31+
}
32+
if (curOpd.Parameter == "[直径]") {
33+
return new Operand(OperandType.NUMBER, _radius * 2);
34+
}
35+
if (curOpd.Parameter == "[高]") {
36+
return new Operand(OperandType.NUMBER, _height);
37+
}
38+
return base.GetParameter(curOpd);
39+
}
40+
}
41+
//调用方法
42+
Cylinder c = new Cylinder(3, 10);
43+
c.TryEvaluate("[半径]*[半径]*pi()", 0.0); //圆底面积
44+
c.TryEvaluate("[直径]*pi()", 0.0); //圆的长
45+
c.TryEvaluate("[半径]*[半径]*pi()*[高]", 0.0); //圆的体积
46+
```
1347

1448

15-
## 类Excel函数
49+
## Excel函数
1650
函数:`逻辑函数``数学与三角函数``文本函数``统计函数``日期与时间函数`
1751

1852
#### 逻辑函数
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using PetaTest;
6+
7+
namespace ToolGood.Algorithm
8+
{
9+
[TestFixture]
10+
class AlgorithmEngineTest_object
11+
{
12+
[Test]
13+
public void Object_test()
14+
{
15+
Cylinder c = new Cylinder(3, 10);
16+
var d = c.TryEvaluate("[半径]*[半径]*pi()", 0.0);
17+
Assert.AreEqual(d, Math.PI * 3 * 3);
18+
var s = c.TryEvaluate("[直径]*pi()", 0.0);
19+
Assert.AreEqual(s, Math.PI * 6);
20+
var v = c.TryEvaluate("[半径]*[半径]*pi()*[高]", 0.0);
21+
Assert.AreEqual(v, Math.PI * 9 * 10);
22+
23+
}
24+
25+
}
26+
27+
28+
public class Cylinder : AlgorithmEngine
29+
{
30+
private int _radius;
31+
private int _height;
32+
public Cylinder(int radius, int height)
33+
{
34+
_radius = radius;
35+
_height = height;
36+
}
37+
38+
protected override Operand GetParameter(Operand curOpd)
39+
{
40+
if (curOpd.Parameter == "[半径]") {
41+
return new Operand(OperandType.NUMBER, _radius);
42+
}
43+
if (curOpd.Parameter == "[直径]") {
44+
return new Operand(OperandType.NUMBER, _radius * 2);
45+
}
46+
if (curOpd.Parameter == "[高]") {
47+
return new Operand(OperandType.NUMBER, _height);
48+
}
49+
return base.GetParameter(curOpd);
50+
}
51+
}
52+
}

ToolGood.Algorithm.Test/ToolGood.Algorithm.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Compile Include="AlgorithmEngine\AlgorithmEngineTest_dateTime.cs" />
4949
<Compile Include="AlgorithmEngine\AlgorithmEngineTest_flow.cs" />
5050
<Compile Include="AlgorithmEngine\AlgorithmEngineTest_math.cs" />
51+
<Compile Include="AlgorithmEngine\AlgorithmEngineTest_object.cs" />
5152
<Compile Include="AlgorithmEngine\AlgorithmEngineTest_string.cs" />
5253
<Compile Include="AlgorithmEngine\AlgorithmEngineTest_sum.cs" />
5354
<Compile Include="PetaTest.cs" />

ToolGood.Algorithm/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
3333
// 方法是按如下所示使用“*”: :
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.10.0")]
36-
[assembly: AssemblyFileVersion("1.1.10.0")]
35+
[assembly: AssemblyVersion("1.1.11.0")]
36+
[assembly: AssemblyFileVersion("1.1.11.0")]

ToolGood.Algorithm/_base/Operand.cs

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,80 @@ public Operand(OperandType type, object value)
1717

1818
this.Value = value;
1919
}
20+
public Operand(OperandType type, short value)
21+
{
22+
this.Type = type;
23+
this.Value = (double)value;
24+
}
2025
public Operand(OperandType type, int value)
2126
{
2227
this.Type = type;
23-
2428
this.Value = (double)value;
2529
}
30+
public Operand(OperandType type, long value)
31+
{
32+
this.Type = type;
33+
this.Value = (double)value;
34+
}
35+
public Operand(OperandType type, ushort value)
36+
{
37+
this.Type = type;
38+
this.Value = (double)value;
39+
}
40+
public Operand(OperandType type, uint value)
41+
{
42+
this.Type = type;
43+
this.Value = (double)value;
44+
}
45+
public Operand(OperandType type, ulong value)
46+
{
47+
this.Type = type;
48+
this.Value = (double)value;
49+
}
50+
public Operand(OperandType type, float value)
51+
{
52+
this.Type = type;
53+
this.Value = (double)value;
54+
}
55+
public Operand(OperandType type, double value)
56+
{
57+
this.Type = type;
58+
this.Value = (double)value;
59+
}
60+
public Operand(OperandType type, DateTime value)
61+
{
62+
this.Type = type;
63+
this.Value = (Date)value;
64+
}
65+
internal Operand(OperandType type, Date value)
66+
{
67+
this.Type = type;
68+
this.Value = (Date)value;
69+
}
70+
public Operand(OperandType type, string value)
71+
{
72+
this.Type = type;
73+
this.Value = value;
74+
}
75+
public Operand(OperandType type, bool value)
76+
{
77+
this.Type = type;
78+
this.Value = value;
79+
}
80+
public Operand(List<Operand> value)
81+
{
82+
this.Type = OperandType.ARRARY;
83+
this.Value = value;
84+
}
2685

2786

28-
29-
public Operand(string opd)
87+
internal Operand(string opd)
3088
{
3189
var lopd = opd.ToLower();
3290
if (lopd == "pi") {
3391
this.Type = OperandType.NUMBER;
3492
this.Value = Math.PI;
35-
} else if (lopd=="e") {
93+
} else if (lopd == "e") {
3694
this.Type = OperandType.NUMBER;
3795
this.Value = Math.E;
3896
} else if (lopd == "true") {
@@ -62,6 +120,9 @@ public Operand(string opd)
62120
#endregion
63121

64122
#region Variable & Property
123+
124+
125+
65126
/// <summary>
66127
/// 操作数类型
67128
/// </summary>
@@ -70,7 +131,16 @@ public Operand(string opd)
70131
/// <summary>
71132
/// 操作数值
72133
/// </summary>
73-
public object Value { get; set; }
134+
internal object Value { get; private set; }
135+
136+
public string Parameter
137+
{
138+
get
139+
{
140+
return Value.ToString().TrimEnd();
141+
}
142+
}
143+
74144
internal double NumberValue
75145
{
76146
get

0 commit comments

Comments
 (0)