public void Enum() { MaybeParse.Enum <Tri>("Good").ShouldBe(Tri.Good); MaybeParse.Enum <Tri>("BAD").ShouldBe(Tri.Bad); MaybeParse.Enum <Tri>("ugly", false).ShouldFail(); MaybeParse.Enum <Tri>("").ShouldFail(); MaybeParse.Enum <Tri>(null).ShouldFail(); }
public void Single() { MaybeParse.Single(12.1f.ToString()).ShouldBe(12.1f); MaybeParse.Single("???").ShouldFail(); MaybeParse.Single(null).ShouldFail(); MaybeParse.SingleInvariant("12.1").ShouldBe(12.1f); MaybeParse.SingleInvariant("???").ShouldFail(); MaybeParse.SingleInvariant(null).ShouldFail(); }
public void Double() { MaybeParse.Double(12.1d.ToString()).ShouldBe(12.1d); MaybeParse.Double("???").ShouldFail(); MaybeParse.Double(null).ShouldFail(); MaybeParse.DoubleInvariant("12.1").ShouldBe(12.1d); MaybeParse.DoubleInvariant("???").ShouldFail(); MaybeParse.DoubleInvariant(null).ShouldFail(); }
public void Int64() { MaybeParse.Int64("12").ShouldBe(12); MaybeParse.Int64("12.1").ShouldFail(); MaybeParse.Int64(null).ShouldFail(); MaybeParse.Int64("???").ShouldFail(); MaybeParse.Int64Invariant("12").ShouldBe(12); MaybeParse.Int64Invariant("12.1").ShouldFail(); MaybeParse.Int64Invariant(null).ShouldFail(); MaybeParse.Int64Invariant("???").ShouldFail(); }
public void Decimal() { MaybeParse.Decimal(12.1m.ToString()).ShouldBe(12.1m); MaybeParse.Decimal("???").ShouldFail(); MaybeParse.Decimal(null).ShouldFail(); const NumberStyles styles = NumberStyles.Number; MaybeParse.Decimal(null, styles, Invariant).ShouldFail(); MaybeParse.Decimal("??", styles, Invariant).ShouldFail(); MaybeParse.Decimal("12.1", styles, Invariant).ShouldBe(12.1m); MaybeParse.DecimalInvariant(null).ShouldFail(); MaybeParse.DecimalInvariant("??").ShouldFail(); MaybeParse.DecimalInvariant("12.1").ShouldBe(12.1m); }
static EnumUtil() { var fromEnums = EnumUtil.GetValues <TFromEnum>(); Enums = new Dictionary <TFromEnum, TToEnum>(fromEnums.Length, EnumUtil <TFromEnum> .Comparer); var unmatched = new List <TFromEnum>(); foreach (var fromEnum in fromEnums) { var @enum = fromEnum; MaybeParse .Enum <TToEnum>(fromEnum.ToString()) .Handle(() => unmatched.Add(@enum)) .Apply(match => Enums.Add(@enum, match)); } Unmatched = unmatched.ToArray(); }