Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a DLL I have the following enumeration.
C#
/// <summary>
/// 
/// </summary>
public enum Shapes
{
  /// <summary>
  /// 
  /// </summary>
  [DescriptionAttribute("A shape with 1 continuous edge that has no corners.")]
  Circle,

  /// <summary>
  /// 
  /// </summary>
  [DescriptionAttribute("A shape 4 equal sides with 4 90° corners.")]
  Square,

  /// <summary>
  /// 
  /// </summary>
  [DescriptionAttribute("A shape 2 pairs of sides that are unequal with 4 90° corners.")]
  Rectangle,
}

How do I get the DescriptionAttribute text to appear in the tooltip instead of the Shape.Circle = 0 at design time within VS?

Thanks

What I have tried:

I haven't found any solutions online yet.
Posted
Updated 26-Feb-18 7:13am
v2
Comments
Richard Deeming 26-Feb-18 12:16pm    
Try putting the description in the XML doc comments.
/// <summary>
/// A shape with 1 continuous edge that has no corners.
/// </summary>
[DescriptionAttribute("A shape with 1 continuous edge that has no corners.")]
Circle,

You didn't specify the platform (WinForms, WPF, or MVC)...

At first blush, I would create a list of Shape objects:

C#
public class MyShape
{
    public ShapeEnum Value { get; set; }
    public string Name { get { return this.Value.ToString(); } }
    public string Description {get; set; }
}

public ListOfShapes:List<MyShape>{}


And then instantiate it in a static class:

C#
public static Globals
{
    public static ListOfShapes Shapes = null;
    static Globals()
    {
        Shapes = new ListOfShapes(){ new MyShape(){Value=ShapeEnum.Circle, Description = "circle description"},...};
    }
}


Bind your control to that list.
 
Share this answer
 
Comments
-Dr_X- 26-Feb-18 12:52pm    
I'm looking for the tooltip in design time, not runtime. I know I can bind it to a dropdown. I want the developers to see the text, not the enum's integer value. -

Two apps, winforms & wpf.

Thanks
#realJSOP 26-Feb-18 13:20pm    
The designer acts like runtime in order to display the forms. If the data is available, t will display at design time (in WPF).
After compiling at least a half dozen times, the XML summary tag is finally appearing with the tooltip.

Thanks,

/// <summary>
///
/// </summary>
public enum Shapes
{
  /// <summary>
  /// "A shape with a continuous edge and has no corners."
  /// </summary>
  [DescriptionAttribute("A shape with a continuous edge and has no corners.")]
  //[EnumToClass(typeof(Circle))]
  Circle,

  /// <summary>
  /// "A shape 4 equal side with 4 90° corners."
  /// </summary>
  [DescriptionAttribute("A shape 4 equal side with 4 90° corners.")]
  //[EnumToClass(typeof(Square))]
  Square,

  /// <summary>
  /// "A shape 2 pairs of side that are unequal with 4 90° corners."
  /// </summary>
  [DescriptionAttribute("A shape 2 pairs of side that are unequal with 4 90° corners.")]
  //[EnumToClass(typeof(Rectangle))]
  Rectangle,
}


Outlaw, I'll give you the answer to you.
 
Share this answer
 
Comments
#realJSOP 26-Feb-18 13:21pm    
I bet it started showing up after you performed a clean/build all action.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900