Forums

Converting an generic Collection to a Typed Collection

Last post 2/10/2010 10:17 AM by Mohsen Benkhellat. 3 replies.
Sort Posts: Previous Next
  • Manel Camps

    Converting an generic Collection to a Typed Collection

    2/9/2010 7:46 AM
    • Not Ranked
    • Joined on 9/24/2008
    • Posts 29

    Hi:

    I have a  function that uses a generic collection as a parameter and the type of the XpObject to retrieve. :

    public void Search(Type Tipo, XPCollection Collection)  (This serach function must work with all kind of objects so i use a generic collection into it)

    When i use into a form with visual insertion of the collection and setting this propertyes of ObjectClassInfo to Tipo the Functions works (i can see this code in the designer Collection.ObjectType= typeof(Objectype)

    but i i work in code:

    XPCollection Collection = new XPCollection()

    Search (typeof(Objecttype),XPCollection Collection)

     

    The function gives an error because the type of the collection is empty ( i try to add an ObjectType cast to XPBaseObject to the collection) If i do

    Collection.ObjecType = typeof(Objectype)    prior to calling search i get an error that says "Cannot change the ObjectType property when XPCollection is not in design or initialization mode.

     

    Any idea in how can i can do this?

     

  • Mohsen Benkhellat

    Re: Converting an generic Collection to a Typed Collection

    2/9/2010 2:11 PM
    • Top 75 Contributor
    • Joined on 11/20/2007
    • Montreal, QC
    • Posts 377

    You may try using type(ObjectType) as a parameter in new XPCollection.

     

    Mohsen

  • Manel Camps

    Re: Converting an generic Collection to a Typed Collection

    2/10/2010 2:31 AM
    • Not Ranked
    • Joined on 9/24/2008
    • Posts 29

    Mohsen:

    It works. I usually define the collection as XpCollection<Type> and this don't work with generic collections. if i use new XPColection(session, Type) it works.

     

    Thank you.

     

  • Mohsen Benkhellat

    Re: Converting an generic Collection to a Typed Collection

    2/10/2010 10:17 AM
    • Top 75 Contributor
    • Joined on 11/20/2007
    • Montreal, QC
    • Posts 377

    You're welcome.

    Glad it helped you.

     

    Mohsen

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.