Message 1 of 3
Strange behavior between List<BuiltInCategory> vs BuiltInCategory[]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've found a strange behavior between List and Array of Enums, not sure if it a c# issue or API issue, I have the below function:
public static IList<Element> GetElements(this Document document,
IEnumerable<BuiltInCategory> categories)
{
List<BuiltInCategory> categoryList = categories.ToList();
var multiCategoryFilter = new ElementMulticategoryFilter(categoryList);
var collector = new FilteredElementCollector(document);
var elements = collector
.WhereElementIsNotElementType()
.WherePasses(multiCategoryFilter)
.ToElements();
return elements;
}
If I call it like this, it doesn't works, neither rise any exception:
(But it should works, as Arrays implements IEnumerable)
var myElements = document.GetElements(new BuiltInCategory[] { BuiltInCategory.OST_Rebar, BuiltInCategory.OST_Walls });
If I call it like this, it works:
var myElements = document.GetElements(new List<BuiltInCategory> { BuiltInCategory.OST_Rebar, BuiltInCategory.OST_Walls });
I've checked the debug information at categoryList = categories.ToList() for the array version, and the Value of items is a number (the Enum int) instead of something like this: OST_Rebar as shown for the List version. Tested in .NetFramework version of API.
Any thoughts?