using Abp.Collections.Extensions;
using Abp.Localization;
using Abp.UI.Inputs;
namespace Abp.Application.Features
{
///
/// Base for implementing .
///
public abstract class FeatureDefinitionContextBase : IFeatureDefinitionContext
{
protected readonly FeatureDictionary Features;
///
/// Initializes a new instance of the class.
///
protected FeatureDefinitionContextBase()
{
Features = new FeatureDictionary();
}
///
/// Creates a new feature.
///
/// Unique name of the feature
/// Default value
/// Display name of the feature
/// A brief description for this feature
/// Feature scope
/// Input type
public Feature Create(string name, string defaultValue, ILocalizableString displayName = null,
ILocalizableString description = null, FeatureScopes scope = FeatureScopes.All, IInputType inputType = null)
{
if (Features.ContainsKey(name))
{
throw new AbpException("There is already a feature with name: " + name);
}
var feature = new Feature(name, defaultValue, displayName, description, scope, inputType);
Features[feature.Name] = feature;
return feature;
}
///
/// Gets a feature with a given name, or null if can not be found.
///
/// Unique name of the feature
///
/// object or null
///
public Feature GetOrNull(string name)
{
return Features.GetOrDefault(name);
}
///
/// Remove feature with given name
///
///
public void Remove(string name)
{
Features.Remove(name);
}
}
}