xarial / xcad

Framework for developing CAD applications for SOLIDWORKS, including add-ins, stand-alone applications, macro features, property manager pages, etc.
https://xcad.net
MIT License
134 stars 29 forks source link

IEnumerable<SwFeature> with ForEach #10

Closed emersonbottero closed 4 years ago

emersonbottero commented 4 years ago

Add supporte for

Features.ForEach(feat =>{ 
      //Do something with feat like getting it's type.
});

today I have to use like that many times.

var Weldment = mPart.Features.First(feat => feat.Name.Contains("Comprimento")) as SwFeature;
artem1t commented 4 years ago

Features is IEnumerable with deferred execution to maximize the performance.

So in below code features will be traversed only up to 'Comprimento' feature instead of getting all features and then enumerating.

var Weldment = mPart.Features.First(feat => feat.Name.Contains("Comprimento")) as SwFeature;

ForEach is an extension of IList (i.e. not deferred type). So you can use the following:

Features.ToList().ForEach(feat =>{ 
      //Do something with feat like getting it's type.
});