public static dynamic Setting <TFeatureEnum>(this TFeatureEnum feature, Enum settingName, IFeatureManifest <TFeatureEnum> featureManifest) where TFeatureEnum : struct { Ensure.That <ArgumentNullException>(featureManifest.IsNotNull(), "featureManifest not supplied.") .And <FeatureNotAvailableException>(feature.IsAvailable(featureManifest), string.Format("Specified feature '{0}' is unavailable.", Enum.GetName(typeof(TFeatureEnum), feature))); try { //todo: refactor string enumItemName = Enum.GetName(settingName.GetType(), settingName); FieldInfo enumItemMember = settingName.GetType().GetField(enumItemName); string enumItemFullName = null; if (enumItemMember != null) { var attribute = (FeatureSettingAttribute) enumItemMember.GetCustomAttributes(typeof(FeatureSettingAttribute), false) .FirstOrDefault(); if (attribute != null) { enumItemFullName = attribute.FullName; } } return(featureManifest[feature].Settings[enumItemFullName ?? enumItemName]); } catch (Exception e) { throw new Exception(string.Format("Unable to find setting \"{0}\".", settingName), e); } }
public static bool IsAvailable <TFeatureEnum>(this TFeatureEnum feature, IFeatureManifest <TFeatureEnum> featureManifest) where TFeatureEnum : struct { Ensure.That <ArgumentNullException>(featureManifest.IsNotNull(), "featureManifest not supplied."); try { return(featureManifest[feature].IsAvailable); } catch (KeyNotFoundException e) { throw new FeatureNotConfiguredException <TFeatureEnum>(feature, e); } }