Exemple #1
0
        public static void Main(string[] args)
        {
            myEnum enummy = myEnum.Val1;
            string val    = enummy.ToDescriptionString();

            Console.ReadLine();
        }
Exemple #2
0
        public static string ToDescriptionString(this myEnum enummy)
        {
            FieldInfo info       = enummy.GetType().GetField(enummy.ToString());
            var       attributes = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attributes?[0].Description ?? enummy.ToString());
        }
Exemple #3
0
        public void ImplicitOperatiorTest1()
        {
            StringEnum <myEnum> target = new StringEnum <myEnum>(myEnum.Alpha);

            myEnum actual = target;

            Assert.AreEqual(myEnum.Alpha, actual);
        }
    public static int toInt(this myEnum value)
    {
        MemberInfo memberInfo = typeof(myEnum).
                                GetMember(value.ToString()).FirstOrDefault();
        XmlEnumAttribute attribute = (XmlEnumAttribute)memberInfo.
                                     GetCustomAttributes(typeof(XmlEnumAttribute), false).FirstOrDefault();

        return(int.Parse(attribute.Name));
    }
Exemple #5
0
        public static void Main()
        {
            var my = new myEnum();

            my = myEnum.Two;
            Console.WriteLine(Marshal.SizeOf(Singleton <string> .Instance));
            Console.WriteLine("T" + myEnum.Two);
            Console.ReadLine();
        }
Exemple #6
0
 public DocumentDummy(FolderDummy folder)
 {
     IdDocument       = 1;
     Topic            = string.Empty;
     Description      = string.Empty;
     CreationDateTime = DateTime.Now;
     Folder           = folder;
     Description      = "___ (folder)";
     Type             = myEnum.TypeThree;
 }
Exemple #7
0
 public DocumentDummy(int id)
 {
     IdDocument       = id;
     Topic            = string.Empty;
     CreationDateTime = DateTime.Now;
     Folder           = new FolderDummy();
     Folder.Name      = "Default Folder - constructor id";
     Description      = "___  (id) " + IdDocument.ToString();
     Type             = myEnum.TypeTwo;
 }
Exemple #8
0
 public DocumentDummy()
 {
     IdDocument       = 1;
     Topic            = string.Empty;
     CreationDateTime = DateTime.Now;
     Folder           = new FolderDummy();
     Folder.Name      = "Default Folder ";
     Description      = "___ () " + IdDocument.ToString();
     Type             = myEnum.TypeOne;
 }
        private void frmExamWizard_Load(object sender, EventArgs e)
        {
            //typesOfTestsTableAdapterMain = new dbDataSetTableAdapters.TypeOfTestsTableAdapter();
            //typesOfTestsTableAdapterMain.ClearBeforeFill = true;
            //typesOfTestsTableAdapterMain.Fill(typesDt);

            int    i     = 0;
            myEnum types = new myEnum();

            do
            {
                CheckBox chkb = new CheckBox();
                chkBoxesList.Add(chkb);
                chkb.Text   = types.sectionTypesArray[i];
                chkb.Parent = pnlTypes;
            } while (++i < types.sectionTypesArray.Length);
        }
Exemple #10
0
        public void TryParseTest()
        {
            StringEnum <myEnum> target = null;

            StringEnum <myEnum> .TryParse("Alpha", ref target);

            myEnum expected = myEnum.Alpha;
            myEnum actual   = target;           // cast to myEnum

            Assert.AreEqual(expected, actual);

            target = null;

            StringEnum <myEnum> .TryParse("beta", ref target);

            expected = myEnum.beta;
            actual   = target;           // cast to myEnum

            Assert.AreEqual(expected, actual);

            target = null;

            StringEnum <myEnum> .TryParse("GAMMA", ref target);

            expected = myEnum.GAMMA;
            actual   = target;           // cast to myEnum

            Assert.AreEqual(expected, actual);

            target = null;

            StringEnum <myEnum> .TryParse("DeltaEpsilon", ref target);

            expected = myEnum.DeltaEpsilon;
            actual   = target;           // cast to myEnum

            Assert.AreEqual(expected, actual);

            // this parse should not work and leave the target as null
            target = null;

            StringEnum <myEnum> .TryParse("badvaluestring", ref target);

            Assert.AreEqual(null, target);
        }
Exemple #11
0
        public void CopyToTest()
        {
            StringEnumList <myEnum> actual = new StringEnumList <myEnum>();

            actual.Add(myEnum.DeltaEpsilon);
            actual.Add(myEnum.DeltaEpsilon);
            actual.Add(myEnum.DeltaEpsilon);
            actual.Add(myEnum.DeltaEpsilon);

            myEnum[] l = new myEnum[] { myEnum.Alpha, myEnum.beta, myEnum.GAMMA, myEnum.DeltaEpsilon };

            actual.CopyTo(l, 0);

            Assert.IsTrue(actual.Contains(myEnum.Alpha));
            Assert.IsTrue(actual.Contains(myEnum.beta));
            Assert.IsTrue(actual.Contains(myEnum.GAMMA));
            Assert.IsTrue(actual.Contains(myEnum.DeltaEpsilon));
        }
        private void frmSectionPrecedence_Load(object sender, EventArgs e)
        {
            //typesOfTestsTableAdapterMain = new dbDataSetTableAdapters.TypeOfTestsTableAdapter();
            //typesOfTestsTableAdapterMain.ClearBeforeFill = true;
            //typesOfTestsTableAdapterMain.Fill(typesDt);

            btnAdd.Enabled    = false;
            btnRemove.Enabled = false;

            int    i     = 0;
            myEnum types = new myEnum();

            lstv1.Items.Clear();
            lstv2.Items.Clear();

            do
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = types.sectionTypesArray[i];
                lstv1.Items.Add(lvi);
            } while (++i < types.sectionTypesArray.Length);
        }
Exemple #13
0
        public void EqualityOperatiorTest()
        {
            StringEnum <myEnum> target = new StringEnum <myEnum>(myEnum.Alpha);;

            StringEnum <myEnum> expected    = new StringEnum <myEnum>(myEnum.Alpha);
            StringEnum <myEnum> notExpected = new StringEnum <myEnum>(myEnum.beta);

            myEnum expected2    = myEnum.Alpha;
            myEnum notExpected2 = myEnum.beta;

            Assert.IsTrue(expected == target);
            Assert.IsTrue(target == expected);

            Assert.IsTrue(notExpected != target);
            Assert.IsTrue(target != notExpected);

            Assert.IsTrue(expected2 == target);
            Assert.IsTrue(target == expected);

            Assert.IsTrue(notExpected2 != target);
            Assert.IsTrue(target != notExpected2);
        }
        public int this[myEnum x]
        {
            get
            {
                Target.Status = 3;
                return 2;
            }

            set
            {
                Target.Status = 4;
            }
        }
        public char this[myEnum x]
        {
            get
            {
                Target.Status = 3;
                return char.MaxValue;
            }

            set
            {
                Target.Status = 4;
            }
        }
        public bool this[myEnum x]
        {
            get
            {
                Target.Status = 3;
                return true;
            }

            set
            {
                if (value)
                    Target.Status = 4;
            }
        }
Exemple #17
0
 public void doIt(myEnum e)
 {
     Console.Out.WriteLine(e);
 }
Exemple #18
0
 public static string ToReport(this myEnum value)
 {
     return(((int)value).ToString("d4"));  // 4 digits, i.e. "101" -> "0101"
 }