Search Unity

GetComponents additional overloading with ICollection<T>

Discussion in 'Scripting' started by koirat, Aug 29, 2019.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    What we got right now is:

    void GetComponents(Type type, List<Component> results);
    void GetComponents<T>(List<T> results);



    It would be useful to have overloads like:

    void GetComponents(Type type, ICollection<Component> results);
    void GetComponents<T>( ICollection<T> results);

    Than it would be possible to specify different collections. One could use for example hashset or custom collection.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
  3. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    It's not about syntactic sugar, even when you write extension method for this, you still need to create List<T> that will be filled with objects. And than you will have to copy objects from this list to ICollection<T>.

    What I suggest is to completely remove need to create List<T> and additional copying of objects to new collection.