Get all features
To get all features, first access the ProductLineModel.FeatureModels
property of the IProject
object to get all feature models. For each feature model, use the AllFeatures
property of the IFeatureModel
object to get all child elements.
public void GetAllFeatures(ICommandContext c, ICommandParams p)
{
IFeatureModelCollection featureModels = c.App.Workspace.CurrentProject.ProductLineModel.FeatureModels;
var features = featureModels.SelectMany(m => m.AllFeatures);
//Exclude feature groups and get features with non-zero assigned models
var assignedFeatures = features.Where(f => f.ClassName != "FeatureGroup" && f.GetAssignedModels().Count() != 0);
//Output
foreach (IFeature feature in assignedFeatures)
{
//Enumerate and output the model names to which the feature is assigned
var modelNames = string.Join(",", feature.GetAssignedModels().Select(f => f.Name));
c.App.Output.WriteLine("sample", $"Feature Name: {feature.Name}, Kind: {feature.VariationKind}, Assigned Models: {modelNames}");
}
}