Skip to content

Commit c852c1b

Browse files
author
linzhijun
committed
fix
1 parent f34b6a8 commit c852c1b

File tree

1 file changed

+20
-45
lines changed

1 file changed

+20
-45
lines changed

csharp/ToolGood.Algorithm/Operand.cs

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -383,27 +383,26 @@ public static Operand CreateNull()
383383
}
384384

385385
#endregion Create
386-
387386
/// <summary>
388387
/// 转数值类型
389388
/// </summary>
390389
/// <param name="errorMessage"></param>
391390
/// <returns></returns>
392-
public virtual Operand ToNumber(string errorMessage = null) { return Error(errorMessage); }
391+
public virtual Operand ToNumber(string errorMessage = null) { return Error(errorMessage ?? "Convert to number error!"); }
393392
/// <summary>
394393
/// 转数值类型
395394
/// </summary>
396395
/// <param name="errorMessage"></param>
397396
/// <param name="args"></param>
398397
/// <returns></returns>
399398
public virtual Operand ToNumber(string errorMessage, params object[] args) { return Error(string.Format(errorMessage, args)); }
400-
399+
401400
/// <summary>
402401
/// 转bool类型
403402
/// </summary>
404403
/// <param name="errorMessage"></param>
405404
/// <returns></returns>
406-
public virtual Operand ToBoolean(string errorMessage = null) { return Error(errorMessage); }
405+
public virtual Operand ToBoolean(string errorMessage = null) { return Error(errorMessage ?? "Convert to bool error!"); }
407406
/// <summary>
408407
/// 转bool类型
409408
/// </summary>
@@ -416,35 +415,35 @@ public static Operand CreateNull()
416415
/// </summary>
417416
/// <param name="errorMessage"></param>
418417
/// <returns></returns>
419-
public virtual Operand ToText(string errorMessage = null) { return Error(errorMessage); }
418+
public virtual Operand ToText(string errorMessage = null) { return Error(errorMessage ?? "Convert to string error!"); }
420419
/// <summary>
421420
/// 转String类型
422421
/// </summary>
423422
/// <param name="errorMessage"></param>
424423
/// <param name="args"></param>
425424
/// <returns></returns>
426425
public virtual Operand ToText(string errorMessage, params object[] args) { return Error(string.Format(errorMessage, args)); }
427-
426+
428427
/// <summary>
429428
/// 转MyDate类型
430429
/// </summary>
431430
/// <param name="errorMessage"></param>
432431
/// <returns></returns>
433-
public virtual Operand ToMyDate(string errorMessage = null) { return Error(errorMessage); }
432+
public virtual Operand ToMyDate(string errorMessage = null) { return Error(errorMessage ?? "Convert to date error!"); }
434433
/// <summary>
435434
/// 转MyDate类型
436435
/// </summary>
437436
/// <param name="errorMessage"></param>
438437
/// <param name="args"></param>
439438
/// <returns></returns>
440439
public virtual Operand ToMyDate(string errorMessage, params object[] args) { return Error(string.Format(errorMessage, args)); }
441-
440+
442441
/// <summary>
443442
/// 转Array类型
444443
/// </summary>
445444
/// <param name="errorMessage"></param>
446445
/// <returns></returns>
447-
public virtual Operand ToArray(string errorMessage = null) { return Error(errorMessage); }
446+
public virtual Operand ToArray(string errorMessage = null) { return Error(errorMessage ?? "Convert to array error!"); }
448447

449448
/// <summary>
450449
/// 转Array类型
@@ -652,7 +651,6 @@ public OperandNumber(decimal obj) : base(obj)
652651
public override Operand ToMyDate(string errorMessage) { return Create((MyDate)NumberValue); }
653652
public override Operand ToMyDate(string errorMessage, params object[] args) { return Create((MyDate)NumberValue); }
654653

655-
public override Operand ToArray(string errorMessage) { return Error(errorMessage ?? "Convert number to array error!"); }
656654
public override string ToString() { return NumberValue.ToString(CultureInfo.InvariantCulture); }
657655
}
658656

@@ -674,9 +672,6 @@ public OperandBoolean(bool obj) : base(obj)
674672
public override Operand ToText(string errorMessage) { return Create(BooleanValue ? "TRUE" : "FALSE"); }
675673
public override Operand ToText(string errorMessage, params object[] args) { return Create(BooleanValue ? "TRUE" : "FALSE"); }
676674

677-
public override Operand ToArray(string errorMessage) { return Error(errorMessage ?? "Convert bool to array error!"); }
678-
679-
public override Operand ToMyDate(string errorMessage) { return Error(errorMessage ?? "Convert bool to date error!"); }
680675
public override string ToString() { return BooleanValue ? "true" : "false"; }
681676
}
682677

@@ -695,7 +690,7 @@ public override Operand ToNumber(string errorMessage)
695690
return Operand.Create(d);
696691
}
697692
if (errorMessage == null) {
698-
return Error("Convert string to number error!");
693+
return Error("Convert to number error!");
699694
}
700695
return Error(errorMessage);
701696
}
@@ -705,15 +700,15 @@ public override Operand ToNumber(string errorMessage, params object[] args)
705700
return Operand.Create(d);
706701
}
707702
if (errorMessage == null) {
708-
return Error("Convert string to number error!");
703+
return Error("Convert to number error!");
709704
}
710705
return Error(string.Format(errorMessage, args));
711706
}
712-
707+
713708

714709
public override Operand ToText(string errorMessage) { return this; }
715710
public override Operand ToText(string errorMessage, params object[] args) { return this; }
716-
711+
717712
public override Operand ToBoolean(string errorMessage)
718713
{
719714
if (TextValue.Equals("true", StringComparison.OrdinalIgnoreCase)) { return True; }
@@ -723,7 +718,7 @@ public override Operand ToBoolean(string errorMessage)
723718
if (TextValue.Equals("1") || TextValue.Equals("是") || TextValue.Equals("有")) { return True; }
724719
if (TextValue.Equals("0") || TextValue.Equals("否") || TextValue.Equals("不是") || TextValue.Equals("无") || TextValue.Equals("没有")) { return False; }
725720
if (errorMessage == null) {
726-
return Error("Convert string to bool error!");
721+
return Error("Convert to bool error!");
727722
}
728723
return Error(errorMessage);
729724
}
@@ -736,18 +731,18 @@ public override Operand ToBoolean(string errorMessage, params object[] args)
736731
if (TextValue.Equals("1") || TextValue.Equals("是") || TextValue.Equals("有")) { return True; }
737732
if (TextValue.Equals("0") || TextValue.Equals("否") || TextValue.Equals("不是") || TextValue.Equals("无") || TextValue.Equals("没有")) { return False; }
738733
if (errorMessage == null) {
739-
return Error("Convert string to bool error!");
734+
return Error("Convert to bool error!");
740735
}
741736
return Error(string.Format(errorMessage, args));
742737
}
743-
738+
744739

745740
public override Operand ToMyDate(string errorMessage)
746741
{
747742
if (TimeSpan.TryParse(TextValue, CultureInfo.InvariantCulture, out TimeSpan t)) { return Create(new MyDate(t)); }
748743
if (DateTime.TryParse(TextValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime d)) { return Create(new MyDate(d)); }
749744
if (errorMessage == null) {
750-
return Error("Convert string to date error!");
745+
return Error("Convert to date error!");
751746
}
752747
return Error(errorMessage);
753748
}
@@ -756,14 +751,14 @@ public override Operand ToMyDate(string errorMessage, params object[] args)
756751
if (TimeSpan.TryParse(TextValue, CultureInfo.InvariantCulture, out TimeSpan t)) { return Create(new MyDate(t)); }
757752
if (DateTime.TryParse(TextValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime d)) { return Create(new MyDate(d)); }
758753
if (errorMessage == null) {
759-
return Error("Convert string to date error!");
754+
return Error("Convert to date error!");
760755
}
761756
return Error(string.Format(errorMessage, args));
762757
}
763-
758+
764759
public override Operand ToArray(string errorMessage)
765760
{
766-
return Error(errorMessage ?? "Convert string to array error!");
761+
return Error(errorMessage ?? "Convert to array error!");
767762
}
768763
public override string ToString()
769764
{
@@ -794,8 +789,6 @@ public OperandMyDate(MyDate obj) : base(obj)
794789
public override Operand ToMyDate(string errorMessage) { return this; }
795790
public override Operand ToMyDate(string errorMessage, params object[] args) { return this; }
796791

797-
public override Operand ToArray(string errorMessage) { return Error(errorMessage ?? "Convert date to array error!"); }
798-
799792
public override string ToString() { return "\"" + DateValue.ToString() + "\""; }
800793
}
801794

@@ -827,16 +820,8 @@ public override Operand ToArray(string errorMessage)
827820
}
828821
return Create(list);
829822
}
830-
return Error(errorMessage ?? "Convert json to array error!");
823+
return Error(errorMessage ?? "Convert to array error!");
831824
}
832-
833-
public override Operand ToBoolean(string errorMessage) { return Error(errorMessage ?? "Convert json to bool error!"); }
834-
835-
public override Operand ToMyDate(string errorMessage) { return Error(errorMessage ?? "Convert json to date error!"); }
836-
837-
public override Operand ToNumber(string errorMessage) { return Error(errorMessage ?? "Convert json to number error!"); }
838-
839-
public override Operand ToText(string errorMessage) { return Error(errorMessage ?? "Convert json to string error!"); }
840825
}
841826

842827
internal sealed class OperandArray : Operand<List<Operand>>
@@ -895,16 +880,6 @@ internal sealed class OperandNull : Operand
895880
{
896881
public override OperandType Type => OperandType.NULL;
897882
public override bool IsNull => true;
898-
899-
public override Operand ToArray(string errorMessage) { return Error(errorMessage ?? "Convert null to array error!"); }
900-
901-
public override Operand ToBoolean(string errorMessage) { return Error(errorMessage ?? "Convert null to bool error!"); }
902-
903-
public override Operand ToText(string errorMessage) { return Error(errorMessage ?? "Convert null to string error!"); }
904-
905-
public override Operand ToNumber(string errorMessage) { return Error(errorMessage ?? "Convert null to number error!"); }
906-
907-
public override Operand ToMyDate(string errorMessage) { return Error(errorMessage ?? "Convert null to date error!"); }
908883
public override string ToString() { return "null"; }
909884
}
910885

0 commit comments

Comments
 (0)