Skip to content

Commit b8a2c41

Browse files
author
lzj
committed
恢复 Operand.cs
1 parent 9243a18 commit b8a2c41

File tree

1 file changed

+14
-62
lines changed

1 file changed

+14
-62
lines changed

csharp/ToolGood.Algorithm2/Operand.cs

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,18 @@ public abstract class Operand : IDisposable
1919
/// False 值
2020
/// </summary>
2121
public static readonly Operand False = Operand.Create(false);
22-
private bool _isError = false;
23-
private string _errorMsg = null;
24-
25-
public Operand() { }
26-
public Operand(string errMsg) { _isError = true; _errorMsg = errMsg; }
27-
28-
2922
/// <summary>
3023
/// 是否为空
3124
/// </summary>
3225
public virtual bool IsNull => false;
3326
/// <summary>
3427
/// 是否出错
3528
/// </summary>
36-
public virtual bool IsError => _isError;
29+
public virtual bool IsError => false;
3730
/// <summary>
3831
/// 错误信息
3932
/// </summary>
40-
public virtual string ErrorMsg => _errorMsg;
33+
public virtual string ErrorMsg => null;
4134
/// <summary>
4235
/// 操作数类型
4336
/// </summary>
@@ -333,12 +326,7 @@ public Operand ToNumber(string errorMessage = null)
333326
return Create(d);
334327
}
335328
}
336-
_isError = true;
337-
if (null == _errorMsg)
338-
{
339-
_errorMsg = errorMessage;
340-
}
341-
return this;
329+
return Error(errorMessage);
342330
}
343331
/// <summary>
344332
/// 转bool类型
@@ -358,12 +346,7 @@ public Operand ToBoolean(string errorMessage = null)
358346
if (TextValue.Equals("1", StringComparison.OrdinalIgnoreCase)) { return Create(true); }
359347
if (TextValue.Equals("0", StringComparison.OrdinalIgnoreCase)) { return Create(false); }
360348
}
361-
_isError = true;
362-
if (null == _errorMsg)
363-
{
364-
_errorMsg = errorMessage;
365-
}
366-
return this;
349+
return Error(errorMessage);
367350
}
368351
/// <summary>
369352
/// 转String类型
@@ -378,12 +361,7 @@ public Operand ToText(string errorMessage = null)
378361
if (Type == OperandType.BOOLEAN) { return Create(BooleanValue ? "TRUE" : "FALSE"); }
379362
if (Type == OperandType.DATE) { return Create(DateValue.ToString()); }
380363

381-
_isError = true;
382-
if (null == _errorMsg)
383-
{
384-
_errorMsg = errorMessage;
385-
}
386-
return this;
364+
return Error(errorMessage);
387365
}
388366
/// <summary>
389367
/// 转Date类型
@@ -400,12 +378,7 @@ public Operand ToDate(string errorMessage = null)
400378
if (TimeSpan.TryParse(TextValue, cultureInfo, out TimeSpan t)) { return Create(new Date(t)); }
401379
if (DateTime.TryParse(TextValue, cultureInfo, DateTimeStyles.None, out DateTime d)) { return Create(new Date(d)); }
402380
}
403-
_isError = true;
404-
if (null == _errorMsg)
405-
{
406-
_errorMsg = errorMessage;
407-
}
408-
return this;
381+
return Error(errorMessage);
409382
}
410383
/// <summary>
411384
/// 转Json类型
@@ -429,12 +402,7 @@ public Operand ToJson(string errorMessage = null)
429402
catch (Exception) { }
430403
}
431404
}
432-
_isError = true;
433-
if (null == _errorMsg)
434-
{
435-
_errorMsg = errorMessage;
436-
}
437-
return this;
405+
return Error(errorMessage);
438406
}
439407
/// <summary>
440408
/// 转Array类型
@@ -466,29 +434,9 @@ public Operand ToArray(string errorMessage = null)
466434
return Create(list);
467435
}
468436
}
469-
_isError = true;
470-
if (null == _errorMsg)
471-
{
472-
_errorMsg = errorMessage;
473-
}
474-
return this;
437+
return Error(errorMessage);
475438
}
476439

477-
///// <summary>
478-
///// 设置失败
479-
///// </summary>
480-
///// <param name="errorMessage"></param>
481-
///// <returns></returns>
482-
//public Operand SetError(string errorMessage)
483-
//{
484-
// _isError = true;
485-
// if (null==_errorMsg)
486-
// {
487-
// _errorMsg = errorMessage;
488-
// }
489-
// return this;
490-
//}
491-
492440
void IDisposable.Dispose() { }
493441

494442

@@ -570,7 +518,7 @@ public static implicit operator Operand(List<double> obj)
570518
abstract class Operand<T> : Operand
571519
{
572520
public T Value { get; private set; }
573-
public Operand(T obj):base()
521+
public Operand(T obj)
574522
{
575523
Value = obj;
576524
}
@@ -616,8 +564,12 @@ public OperandArray(List<Operand> obj) : base(obj) { }
616564
class OperandError : Operand
617565
{
618566
public override OperandType Type => OperandType.ERROR;
619-
public OperandError(string msg):base(msg)
567+
public override bool IsError => true;
568+
private string _errorMsg;
569+
public override string ErrorMsg => _errorMsg;
570+
public OperandError(string msg)
620571
{
572+
_errorMsg = msg;
621573
}
622574
}
623575

0 commit comments

Comments
 (0)