コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }