Author Topic: An ObjectIdList Class  (Read 3802 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
An ObjectIdList Class
« on: October 01, 2007, 07:30:13 AM »
Thought this might be useful, based off of Tony’s TypedValueList class.

Code: [Select]
public class ObjectIdList : List<ObjectId>
  {
    public ObjectIdList()
    {
    }
    public ObjectIdList(ObjectId src)
    {
      base.Add(src);
    }
    public ObjectIdList(ObjectId[] src)
    {
      base.AddRange(src);
    }
    public ObjectIdList(ObjectIdList src)
    {
      base.AddRange(src);
    }
    public ObjectIdList(ObjectIdCollection src)
    {
      foreach (ObjectId oid in src)
        base.Add(oid);
    }
    public static implicit operator ObjectIdList(ObjectId[] src)
    {
      return ((src != null) ? new ObjectIdList(src) : null);
    }
    public static implicit operator ObjectIdList(ObjectIdCollection src)
    {
      return ((src != null) ? new ObjectIdList(src) : null);
    }
    public static implicit operator ObjectId[](ObjectIdList src)
    {
      return ((src != null) ? src.ToArray() : null);
    }
    public static implicit operator ObjectIdCollection(ObjectIdList src)
    {
      return ((src != null) ? new ObjectIdCollection(src.ToArray()) : null);
    }
  }
« Last Edit: October 02, 2007, 09:09:45 AM by Daniel »

Glenn R

  • Guest
Re: An ObjectIdList Class
« Reply #1 on: October 01, 2007, 08:31:57 PM »
Hi Daniel,

Nicely done, however, I'm failing to see the use/benefit of this...can you elude as to your thoughts for creating this and possible usage scenarios? Also, how about explicit conversions as well?

LE

  • Guest
Re: An ObjectIdList Class
« Reply #2 on: October 01, 2007, 10:26:56 PM »
Daniel;

Is that Alfonso Arau in your avatar?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
Re: An ObjectIdList Class
« Reply #3 on: October 02, 2007, 01:01:11 AM »
Hi Daniel,

Nicely done, however, I'm failing to see the use/benefit of this...can you elude as to your thoughts for creating this and possible usage scenarios? Also, how about explicit conversions as well?

It’s only to add a little flexibility to the collection by being able to use the built-in member methods of List. I.e. AddRange(),  Foreach(delegate or lambda expressions)  etc.
I didn’t have a need for explicit operators, but I am sure that could be added. I posted it to show that this technique could be used on other collections where the additional flexibility might convenient i.e, searching, sorting, the future use of in memory LinQ queries etc.

Dan

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
Re: An ObjectIdList Class
« Reply #4 on: October 02, 2007, 01:05:52 AM »
Daniel;

Is that Alfonso Arau in your avatar?

Yes sir it is, AKA "El Guapo" from The Three Amigos.  :lol:
But I am El Guapo too. We are both El Guapo  8-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: An ObjectIdList Class
« Reply #5 on: October 02, 2007, 04:51:19 AM »
.............

Yes sir it is, AKA "El Guapo" from The Three Amigos.  :lol:
But I am El Guapo too. We are both El Guapo  8-)


polymorphism in action ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: An ObjectIdList Class
« Reply #6 on: October 02, 2007, 08:41:20 AM »
roflmao Kerry!