cast of arrays with a given type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • am72de@yahoo.de

    cast of arrays with a given type

    Hi all,

    I have to write an editor for Visual Studio. It's one editor for
    different kind of Arrays: Button[], TextBox[] and so on.
    The intern array is Control[], so I can use it for all of the
    inherited controls.

    But now I don't know how to convert a Control[] back to the given
    type.

    Please see the following example:

    Button[] btns = new Button[30];
    Control[] ctls = (Control[])btns;

    The obvious way to cast the ctls back would be:

    Button[] btns2 = (Button[])ctls;

    Does anybody know how to convert it back with only a given type?

    Something like that: Button[] btns3 = ctls as typeof(Button[]);

    Thanks in advance
    Andy
  • Ben Voigt [C++ MVP]

    #2
    Re: cast of arrays with a given type

    Unfortunately the editor should handle as many Controls, Buttons and
    even Interfaces as possible. All works fine, except the automatic back
    cast via a type.
    Because the UITypeEditor.Ed itValue gives me only the
    Propertydescrip tor - and I don't want to cast every single type - I
    thought there has to be a better and simpler way.
    You need to use the PropertyDescrip tor.SetValue and friends, there shouldn't
    be any casting of the control type required (the component parameter is type
    System::Object) .


    Comment

    Working...