Book a Demo

Author Topic: TaggedValues vs. TaggedValuesEx  (Read 4661 times)

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
TaggedValues vs. TaggedValuesEx
« on: August 16, 2010, 01:04:11 pm »
While Element.TaggedValues and Element.TaggedValuesEx both return collections of type TaggedValue, apparently Collection.GetByName(name) only works on TaggedValues, not TaggedValuesEx. Is this intentional?

Running EA 8.0 build 861, BTW...

UPDATE:

Here's the code that didn't work:
Code: [Select]
try
{
...
TaggedValue tag = elem.TaggedValuesEx.GetByName(name);
...
}
catch ...
{
...
return null;
}
This always returns null.

Here's the workaround:
Code: [Select]
           try
            {
                TaggedValue tag = null;

                foreach (TaggedValue t in elem.TaggedValuesEx)
                {
                    if (t.Name == name)
                    {
                        tag = t;
                        break;
                    }
                }

                return tag;
            }
            catch (Exception e)
            {
                EAConnector.LastError = e.Message;
                return null;
            }
I kept the try-catch for the time being.
« Last Edit: August 16, 2010, 01:11:27 pm by fwoolz »
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: TaggedValues vs. TaggedValuesEx
« Reply #1 on: August 16, 2010, 04:01:53 pm »
GetByName is not supported on all collections.  TaggedValuesEx is more likely to have duplicate tags.

beginner

  • Guest
Re: TaggedValues vs. TaggedValuesEx
« Reply #2 on: August 16, 2010, 06:29:10 pm »
I had to learn that lesson too some years ago. Probably the help should be a bit more explicit on which collections support GetByName and which don't.

b.

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
Re: TaggedValues vs. TaggedValuesEx
« Reply #3 on: August 17, 2010, 03:50:06 am »
Here's what the help file says:

GetByName (string Name)ObjectGets an item in the current collection by Name.

If the collection does not contain any items, the method returns a null value. If the collection contains items, but it was unable to find an object with the specified name, the method raises an exception.

Only supported for the following collections: Model, Package, Element, Diagram, and element TaggedValue.
Parameters:

Name: String
Since TaggedValuesEx is a collection of TaggedValue objects, the Help file would lead one (well, some at least) to believe that both TaggedValues and TaggedValuesEx support GetByName. And since Element names aren't required to be unique (nor are Package names, Diagram names, or even Model names (AFAIK)), the fact that TaggedValuesEx is more likely to have duplicate tag names seems like a weak justification for treating TaggedValues and TaggedValuesEx differently. Particularly since it is also possible to have duplicates in TaggedValues (if duplicate tags are permitted).

By the way, how does GetByName(name) react if it finds duplicate names in a collection?
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


beginner

  • Guest
Re: TaggedValues vs. TaggedValuesEx
« Reply #4 on: August 17, 2010, 08:16:17 pm »
Bugs by design. Probably EA will take the first and let you go with that. Basically it should return a collection but then you get inn trouble with different languages which can't cope with such varying results.

b.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: TaggedValues vs. TaggedValuesEx
« Reply #5 on: August 18, 2010, 03:19:51 pm »
Yes I'm pretty convinced that is what EA will do.
That is one of the reasons I never use the getByName function of the collections.

In fact I try to avoid the EA.Collection as much as possible. The first chance I get I throw the elements into a "real" (language provided) Collection and work from that.

Geert