示例#1
0
        /// <summary>
        ///     Parses the specified identifier.
        ///     the string format is as follows:
        ///     key1:value1|key2:value2|key3:value3|...
        ///     IMPORTANT: this method depends on EnumTextAttribute class and
        ///     hence all IdFields texts have to be used first.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <returns>
        ///     A <see cref="PaperBallotIdentifier" /> containing the specified
        ///     identifier.
        /// </returns>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="12/24/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        public static PaperBallotIdentifier Parse(string identifier)
        {
            PaperBallotIdentifier pbiId = new PaperBallotIdentifier();

            string[] pairs = identifier.Split(SepMajor),
            pair;
            IdField key;

            foreach (string strPair in pairs)
            {
                pair = strPair.Split(SepMinor);
                if (pair.Length != 2)
                {
                    continue;
                }

                try
                {
                    key = (IdField)EnumTextAttribute.GetValue(pair[0]);
                    pbiId.Set(key, pair[1]);
                }
                catch (Exception)
                {
                    // simply ignore the exception and drop the current field
                    // since the field is not supported or is mispelled
                }
            }

            return(pbiId);
        }
示例#2
0
        public void GetEnumValue()
        {
            string myText = "Testing Enum Text Attributes";
            Enum   myEnum = EnumTextAttribute.GetValue(myText);

            Assert.AreEqual(myEnum, EnumTest.EnumTypeWithTextAttribute);

            myEnum = EnumTextAttribute.GetValue("some text here");
            Assert.IsNull(myEnum);

            myEnum = EnumTextAttribute.GetValue("Another text here");
            Assert.IsNull(myEnum);

            EnumTextAttribute.GetText(EnumTest.EnumTypeWithAnotherText);
            myEnum = EnumTextAttribute.GetValue("Another text here");
            Assert.IsNotNull(myEnum);
            Assert.AreNotEqual(myEnum, EnumTest.EnumTypeWithTextAttribute);
            Assert.AreNotEqual(myEnum, EnumTest.EnumTypeWithNoTextAttribute);
            Assert.AreEqual(myEnum, EnumTest.EnumTypeWithAnotherText);
        }