public static void Main(string[] args) { myEnum enummy = myEnum.Val1; string val = enummy.ToDescriptionString(); Console.ReadLine(); }
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()); }
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)); }
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(); }
public DocumentDummy(FolderDummy folder) { IdDocument = 1; Topic = string.Empty; Description = string.Empty; CreationDateTime = DateTime.Now; Folder = folder; Description = "___ (folder)"; Type = myEnum.TypeThree; }
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; }
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); }
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); }
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); }
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; } }
public void doIt(myEnum e) { Console.Out.WriteLine(e); }
public static string ToReport(this myEnum value) { return(((int)value).ToString("d4")); // 4 digits, i.e. "101" -> "0101" }