मुझे यकीन है कि यह कितना मदद करता है नहीं कर रहा हूँ, लेकिन मुझे लगता है कि इस तरह दिखता है Enum पर एक विस्तार विधि का उपयोग करें:
/// <summary>
/// Returns the value of the description attribute attached to an enum value.
/// </summary>
/// <param name="en"></param>
/// <returns>The text from the System.ComponentModel.DescriptionAttribute associated with the enumeration value.</returns>
/// <remarks>
/// To use this, create an enum and mark its members with a [Description("My Descr")] attribute.
/// Then when you call this extension method, you will receive "My Descr".
/// </remarks>
/// <example><code>
/// enum MyEnum {
/// [Description("Some Descriptive Text")]
/// EnumVal1,
///
/// [Description("Some More Descriptive Text")]
/// EnumVal2
/// }
///
/// static void Main(string[] args) {
/// Console.PrintLine(MyEnum.EnumVal1.GetDescription());
/// }
/// </code>
///
/// This will result in the output "Some Descriptive Text".
/// </example>
public static string GetDescription(this Enum en)
{
var type = en.GetType();
var memInfo = type.GetMember(en.ToString());
if (memInfo != null && memInfo.Length > 0)
{
var attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs != null && attrs.Length > 0)
return ((DescriptionAttribute)attrs[0]).Description;
}
return en.ToString();
}
आप अपने वस्तु पर कोई कस्टम गुण गेटर इस्तेमाल कर सकते हैं वापस जाने के लिए नाम:
public class TestResult
{
public string TestDescription { get; set; }
public ExpectationResult RequiredExpectationResult { get; set; }
public ExpectationResult NonRequiredExpectationResult { get; set; }
/* *** added these new property getters *** */
public string RequiredExpectationResultDescr { get { return this.RequiredExpectationResult.GetDescription(); } }
public string NonRequiredExpectationResultDescr { get { return this.NonRequiredExpectationResult.GetDescription(); } }
}
फिर "RequiredExpectationResultDescr" और "NonRequiredExpectationResultDescr" गुण के लिए अपने ग्रिड बाँध।
कि एक छोटे से अधिक जटिल हो सकता है, लेकिन इसकी 1 बात मैं :)
धन्यवाद मार्क! हमारे EnumHelper (रैली25rs के उत्तर के पहले भाग के समान) के साथ संयुक्त, यह सुरुचिपूर्ण समाधान खूबसूरती से काम करता है - डेटाग्रिड व्यू में। दुर्भाग्य से मैंने पाया कि DevExpress.XtraGrid.GridControl ** ** ** टाइपकॉन्टर विशेषता का पता नहीं लगाता है। आह। लेकिन आपका जवाब स्पष्ट रूप से सही है। – TrueWill
... और आपने मुझे सही दिशा में इंगित किया। मैंने पाया कि डेवलपर एक्सप्रेस इस का समर्थन करने की योजना नहीं बना रहा है, और यह कामकाज प्रदान करता है: http://www.devexpress.com/Support/Center/p/CS2436.aspx – TrueWill