Add a feature
This explains how to add a feature.
Add a feature to a feature model
To add a feature to a feature model, use the AddNewFeature
method of the IFeatureModel
object. The destination is the end of the list, and the type is Mandatory
.
public void AddNewFeature(ICommandContext c, ICommandParams p)
{
IFeatureModel featureModel = c.App.Workspace.CurrentProject.ProductLineModel.FeatureModels.FirstOrDefault();
//Add a feature with the specified name
featureModel.AddNewFeature("Preceding vehicle detection method");
}
Add a feature as a child element to a feature
To add a feature as a child element to a feature, use the AddNewFeatureAt
method of the IFeatureModel
object. The destination is the end of the list.
The following is an example of adding a feature named "millimeter wave radar" as a child element of "preceding vehicle detection method".
The types of features that can be added are as follows.
Feature type name | Feature type |
---|---|
Mandatory | |
Optional | |
Select one | Alternative |
Select one or more | Or |
public void AddNewFeatureAt(ICommandContext c, ICommandParams p)
{
IFeatureModel featureModel = c.App.Workspace.CurrentProject.ProductLineModel.FeatureModels.FirstOrDefault();
IFeature parentFeature = featureModel.GetFeature("preceding vehicle detection method");
featureModel.AddNewFeatureAt("millimeter wave radar", "Alternative", parentFeature);
}