Component editor for Enumerated Type - Generated Output RRS feed

  • Question

  • Well,

    I posted this here but somebody moved it claiming it had nothing to do with Extensibility, Quoting "the forum for VSX is about creating editors not using a specific one".  However, I believe the individual's command of English was a little lacking and they misunderstood the question.

    So I am re-posting with the clarification:  This IS about creating an editor, but it also about controlling the output generated from the editor.  When Dealing with Enumerated types, the initial default editor for Enum types is a simple combo box that drops down and allows the developer to select one of the values. 

    I have written a Editor to expand upon those Enum types that also attributed with the FlagsAttribute().  (Much like the Anchor Property for Controls).  Now, My editor (which is written already) is a simple CheckedListBox that allows the developer to Check and Uncheck values, and then collapses them in bitwise fashion for the final result.  ie: 2, 16, 64 = 82 is the final value, (which is of course returned in the type of whatever Enum type is being edited). 

    However, I noticed that in the forms designer I get this kind of out put:
    .MyControl1.Flags = CType
    ((((Project1.Namespace1.EnumFlag.Value1 or
     Project1.Namespace1.EnumFlag.Value2) _
    Or Project1.Namespace1.EnumFlag.Value3) _
    Or Project1.Namespace1.EnumFlag.Value4), Project1.Namespace1.EnumFlag)

    I believe if I want to adjust the output that is generated in the Forms Designer.vb file, I would need to create a TypeConverter as well for the Enum type, but I am uncertain as to how I would go about such a thing.

    With Reference (instance) types I would simply make the type converter handle the conversion to an "InstanceDescriptor" and all would be well, but an Enum type is a Value type, so I not sure how much of the "InstanceDescriptor" is accurate.

    So I'm asking with either the Editor OR with a TypeConverter is there a way for me to control the Output (generated code) of the Flagged Enum value.

    A) First I'd like to be able to eliminate the unnecessary CType() type cast.  The Property type is Project1.Namespace1.EnumFlag so why the need to Cast it to its own type, regardless of the bitwise "Or" operation.

    B) Is there a way to allow for "Combined" flag values?  LIke 1,2,4 and 8 are Individual Flags, and 15 = AllValues, so I would like to create the output as:  My.MyControl1.Flags= Project1.Namespace1.EnumFlag.AllValues, not as all enum fields or'ed together.


    Jaeden "Sifo Dyas" al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Friday, June 11, 2010 5:38 PM