Replies: 3 comments 14 replies
-
Consider the following: IEnumerable<Entity> entities = polylines.Cast<Entity>();
IEnumerable<ObjectId> ids = entities.Select(e => e.ObjectId);
ObjectIdCollection idCollection = new ObjectIdCollection(ids.ToArray()); Before Group gp = db.Groups.Element("1", true);
gp.Clear();
gp.InsertAt(0, idCollection); // inserting at a specific index, must use ObjectIdCollection After Group gp = db.Groups.Element("1", true);
gp.Add(ids); // add IEnumerable of ObjectId
gp.Add(entities); // add IEnumerable of Entities
// caller should not worry about inserting at a specific index,
// or passing ObjectIdCollections Perhaps this could be an extension method on the |
Beta Was this translation helpful? Give feedback.
-
Hi Ben, thanks, interesting idea. I agree that writing checks is a pain sometimes. In the above case the check could be simplified to something like this: var group = db.Groups.Contains("Test")
? db.Groups.Element("Test")
: db.Groups.Create("Test"); By implementing a method like CreateOrFind, in my opinion, it saves too little code on the client side, so I think the new method on the API (CreateOrFind) side would not be justfied. But, on the other side, CreateOrFind is a perfect candidate for an extension method (in the client code): public static class GroupContainerExtensions
{
public static Group CreateOrFind(this GroupContainer container, string groupName)
=> container.Contains(groupName)
? container.Elemenet(groupName)
: container.Create(groupName);
} So in my opinion an extension method is definitively the way to go. |
Beta Was this translation helpful? Give feedback.
-
Hi Wolfgang, I wish to throw in my final two cents based on your response:
The idea being: only a little bit of client code is saved, rendering a public API not justifiable. I do agree - it saves little code. In response, I would adduce my own experience: in rails - which are full of such handy methods and also in a code sample within Linq2Acad - small code saved here and there is very pleasing - to me and aruably to others. I merely propose this as an idea, and leave it to your discretion to reject or accept it, as you see fit. rgds Ben |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Wolfgang,
Would you accept a PR for the following:
Before
After
Without it, we'd have to add a conditional to check if the
Group
exists, and if not, to return the appropriate result. The proposal is a very Rails paradigm - which is very handy to use. Now that I think about it, it could probably apply to any of the named objects dictionaries.Please LMK your thoughts?
Ben
Beta Was this translation helpful? Give feedback.
All reactions