public void EnumTextValueAttributeTestCtor() { // arrange/act var result = new EnumTextValueAttribute(); // assert Assert.That(result.Value, Is.EqualTo(string.Empty)); }
public void EnumTextValueAttributeTestCtorWithValue(string value) { // arrange/act var result = new EnumTextValueAttribute(value); // assert Assert.That(result.Value, Is.EqualTo(value)); }
public void EnumTextValueAttributeTestHashCode() { // arrange var str = "text"; // act var attrib = new EnumTextValueAttribute(str); // assert Assert.That(attrib.GetHashCode(), Is.EqualTo(str.GetHashCode())); }
public void EnumTextValueAttributeTestDefault() { // arrange/act var attrib1 = new EnumTextValueAttribute(string.Empty); var attrib2 = new EnumTextValueAttribute("bob"); var attrib3 = EnumTextValueAttribute.Default; // assert Assert.That(attrib1.IsDefaultAttribute, Is.EqualTo(true)); Assert.That(attrib2.IsDefaultAttribute, Is.EqualTo(false)); Assert.That(attrib3.IsDefaultAttribute, Is.EqualTo(true)); }
public void EnumStringValueAttributeTestEquals(string value, string second, bool expected) { // arrange var attrib1 = new EnumTextValueAttribute(value); var attrib2 = new EnumTextValueAttribute(second); //act var result = attrib1.Equals(attrib2); // assert Assert.That(result, Is.EqualTo(expected)); }
/// <summary> /// 根据枚举的值,得到枚举对应的文本 /// </summary> /// <param name="value"></param> /// <returns></returns> public static string GetEnumOptText(Type type, int value) { FieldInfo[] fields = type.GetFields(); for (int i = 1, count = fields.Length; i < count; i++) { FieldInfo field = fields[i]; if (((int)Enum.Parse(type, field.Name)).ToString() == value.ToString()) { object[] objs = field.GetCustomAttributes(typeof(EnumTextValueAttribute), false); if (objs == null || objs.Length == 0) { return(field.Name); } else { EnumTextValueAttribute da = (EnumTextValueAttribute)objs[0]; return(da.Text); } } } return(""); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that /// use composition-based implementation to create any child controls they /// contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { // Start with a clean form base.Controls.Clear(); cboFieldName = new DropDownList(); cboFieldName.ID = "cboFieldName"; cboFieldName.SkinID = "cboFieldName"; if (!base.DesignMode) { GridView1 = (GridView)this.NamingContainer.FindControl(this.GridViewControlID); TypedDataSource = (DataSourceControl)this.NamingContainer.FindControl(GridView1.DataSourceID); Type[] typeArguments = TypedDataSource.GetType().BaseType.GetGenericArguments(); _businessEntityType = typeArguments[0].FullName; #region Set up the fields drop down list using the list of table columns Type enumType = EntityUtil.GetType(string.Format("{0}Column", _businessEntityType)); Array c = Enum.GetValues(enumType); for (int i = 0; i < c.Length; i++) { ColumnEnumAttribute cea = EntityHelper.GetAttribute <ColumnEnumAttribute>((Enum)c.GetValue(i)); EnumTextValueAttribute etv = EntityHelper.GetAttribute <EnumTextValueAttribute>((Enum)c.GetValue(i)); // only show fields that we can realistically search against switch (cea.DbType) { case System.Data.DbType.AnsiString: case System.Data.DbType.AnsiStringFixedLength: case System.Data.DbType.Boolean: case System.Data.DbType.Byte: case System.Data.DbType.Currency: case System.Data.DbType.Date: case System.Data.DbType.DateTime: case System.Data.DbType.Decimal: case System.Data.DbType.Double: case System.Data.DbType.Int16: case System.Data.DbType.Int32: case System.Data.DbType.Int64: case System.Data.DbType.SByte: case System.Data.DbType.Single: case System.Data.DbType.String: case System.Data.DbType.StringFixedLength: case System.Data.DbType.Time: case System.Data.DbType.UInt16: case System.Data.DbType.UInt32: case System.Data.DbType.UInt64: case System.Data.DbType.VarNumeric: case System.Data.DbType.Xml: #region Add fields to the dropdown collection ListItem li = new ListItem(); li.Text = etv != null && !string.IsNullOrEmpty(etv.Text) ? EntityHelper.GetPascalSpacedName(etv.Text) : EntityHelper.GetPascalSpacedName(cea.Name); li.Value = cea.Name; cboFieldName.Items.Add(li); #endregion break; default: break; } } #endregion } else { cboFieldName.Items.Add(new ListItem("FieldName", "FieldValue")); } #region UI implementation cboOperator = new DropDownList(); cboOperator.ID = "cboOperator"; cboOperator.SkinID = "cboOperator"; cboOperator.Items.Add(new ListItem("contains", "0")); cboOperator.Items.Add(new ListItem("starts with", "1")); cboOperator.Items.Add(new ListItem("equals", "2")); cboOperator.Items.Add(new ListItem("ends with", "3")); txtKeyword = new TextBox(); txtKeyword.ID = "txtKeyword"; txtKeyword.SkinID = "txtKeyword"; Label lblLookFor = new Label(); lblLookFor.ID = "lblLookFor"; lblLookFor.SkinID = "lblLookFor"; lblLookFor.Text = LookForText; Label lblWhich = new Label(); lblWhich.ID = "lblWhich"; lblWhich.SkinID = "lblWhich"; lblWhich.Text = WhichText; Button cmdSearch = new Button(); cmdSearch.ID = "cmdSearch"; cmdSearch.SkinID = "cmdSearch"; cmdSearch.Text = "Search"; cmdSearch.CausesValidation = CausesValidation; cmdSearch.Click += new EventHandler(cmdSearch_Click); Button cmdReset = new Button(); cmdReset.ID = "cmdReset"; cmdReset.SkinID = "cmdReset"; cmdReset.Text = "Reset"; cmdReset.CausesValidation = CausesValidation; cmdReset.Click += new EventHandler(cmdReset_Click); Table tbl = new Table(); tbl.SkinID = "tblSearchPanel"; TableRow tr = new TableRow(); TableCell td; td = new TableCell(); td.Controls.Add(lblLookFor); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cboFieldName); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(lblWhich); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cboOperator); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(txtKeyword); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cmdSearch); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cmdReset); tr.Cells.Add(td); tbl.Rows.Add(tr); #endregion base.Controls.Add(tbl); base.ClearChildViewState(); }