Skip to content

Commit 27f400e

Browse files
committed
修改 README.md ,整理代码
1 parent e209934 commit 27f400e

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ ToolGood.Algorithm֧
1818
```
1919
支持常量`pi`,`e`,`true`,`false`
2020

21-
数字转bool,非零为真
21+
数字转bool,非零为真,零为假。bool转数字,假为0,真为1。
2222

2323
索引默认为`Excel索引`,如果想用c#索引,请设置`UseExcelIndex``false`
2424

25-
2625
## 自定义参数
2726
``` csharp
2827
//定义圆柱信息
@@ -55,7 +54,10 @@ ToolGood.Algorithm֧
5554
c.TryEvaluate("[半径]*[半径]*pi()", 0.0); //圆底面积
5655
c.TryEvaluate("[直径]*pi()", 0.0); //圆的长
5756
c.TryEvaluate("[半径]*[半径]*pi()*[高]", 0.0); //圆的体积
57+
58+
c.TryEvaluate("p('半径')*[半径]*pi()*[高]", 0.0); //圆的体积
5859
```
60+
参数以方括号定义,如 `[参数名]`。变量参数可以用`p(参数名)`
5961

6062

6163
## Excel函数

ToolGood.Algorithm/_base/Date.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace ToolGood.Algorithm
77
{
8-
class Date
8+
class Date
99
{
1010
public Date(string str)
1111
{
@@ -98,11 +98,11 @@ public override string ToString()
9898
((DateTime)this).ToString("yyyy-MM-dd HH:mm:ss");
9999
} else if (Year > 0 && Hour > 0) {
100100
((DateTime)this).ToString("yyyy-MM-dd HH:mm");
101-
} else if (Year > 0 ) {
101+
} else if (Year > 0) {
102102
((DateTime)this).ToString("yyyy-MM-dd");
103103
} else if (Hour > 0 && Second > 0) {
104104
((DateTime)this).ToString("HH:mm:ss");
105-
} else {
105+
} else {
106106
((DateTime)this).ToString("HH:mm:ss");
107107
}
108108
}
@@ -125,7 +125,7 @@ public static implicit operator DateTime(Date date)
125125
}
126126
public static implicit operator TimeSpan(Date date)
127127
{
128-
return new TimeSpan( date.Hour, date.Minute, date.Second);
128+
return new TimeSpan(date.Hour, date.Minute, date.Second);
129129
}
130130

131131
public static implicit operator Date(double days)

ToolGood.Algorithm/_base/Operand.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,23 @@ internal Operand(string opd)
133133
/// </summary>
134134
internal object Value { get; private set; }
135135

136-
public string Parameter
137-
{
138-
get
139-
{
136+
public string Parameter {
137+
get {
140138
return Value.ToString().TrimEnd();
141139
}
142140
}
143141

144-
internal double NumberValue
145-
{
146-
get
147-
{
142+
internal double NumberValue {
143+
get {
148144
if (Type == OperandType.BOOLEAN) {
149145
return (bool)Value ? 1 : 0;
150146
}
151147
return (double)Value;
152148
}
153149
}
154150
internal string StringValue { get { return Value.ToString(); } }
155-
internal bool BooleanValue
156-
{
157-
get
158-
{
151+
internal bool BooleanValue {
152+
get {
159153
if (Type == OperandType.NUMBER) {
160154
if (Value is double) {
161155
return (double)Value != 0;
@@ -226,8 +220,8 @@ public bool CanTransitionTo(OperandType operandType)
226220
if (operandType == Type) return true;
227221
if (Type == OperandType.ERROR) return false;
228222

229-
if (operandType== OperandType.STRING) return true;
230-
if (operandType== OperandType.NUMBER) {
223+
if (operandType == OperandType.STRING) return true;
224+
if (operandType == OperandType.NUMBER) {
231225
return IsNumber(this.Value);
232226
}
233227
if (operandType == OperandType.DATE) {
@@ -274,9 +268,9 @@ public static OperandType ConvertOperand(string opd)
274268
/// <returns></returns>
275269
public static bool IsBoolean(object value)
276270
{
277-
if (value is Int16|| value is Int32|| value is Int64||
278-
value is UInt16|| value is UInt32|| value is UInt64||
279-
value is double|| value is float|| value is decimal) {
271+
if (value is Int16 || value is Int32 || value is Int64 ||
272+
value is UInt16 || value is UInt32 || value is UInt64 ||
273+
value is double || value is float || value is decimal) {
280274
return true;
281275
}
282276

ToolGood.Algorithm/_base/OperandType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum OperandType
2323
/// 日期
2424
/// </summary>
2525
DATE,
26-
26+
2727
/// <summary>
2828
/// 数组
2929
/// </summary>

ToolGood.Algorithm/_base/Operator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static bool IsBinaryOperator(ref Stack<object> tokens, ref Stack<Operator
8989
}
9090
object token = tokens.Peek();
9191
if (token is Operand) {
92-
return operators.Peek().Type != OperatorType.LB ;
92+
return operators.Peek().Type != OperatorType.LB;
9393
} else {
9494
return ((Operator)token).Type == OperatorType.RB;
9595
}

ToolGood.Algorithm/_base/OperatorType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal enum OperatorType
2424
/// 创建数组
2525
/// </summary>
2626
CREATEARRARY,
27-
27+
2828
/// <summary>
2929
/// 函数
3030
/// </summary>
@@ -126,7 +126,7 @@ internal enum OperatorType
126126
/// <summary>
127127
/// 逻辑或,|,OR
128128
/// </summary>
129-
OR,
129+
OR,
130130

131131
/// <summary>
132132
/// 逗号,comma

0 commit comments

Comments
 (0)