/// <summary> /// Test whether <paramref name="model"/> has feature <typeparamref name="TFeature"/>. /// </summary> /// <typeparam name="TFeature">Type of required feature.</typeparam> /// <param name="condition">Ensure condition helper.</param> /// <param name="model">Model test feature on.</param> /// <exception cref="ArgumentOutOfRangeException">When <paramref name="model"/> doesn't have feature of type <typeparamref name="TFeature"/>.</exception> public static void HasFeature <TFeature>(this EnsureConditionHelper condition, IFeatureModel model) { Ensure.NotNull(condition, "condition"); Ensure.NotNull(model, "model"); TFeature feature; if (!model.TryWith(out feature)) { throw Ensure.Exception.ArgumentOutOfRange("model", "Feature of type '{0}' is required on '{1}'.", typeof(TFeature).FullName, model); } }
/// <summary> /// Tries to retrieve object of type <typeparamref name="TFeature"/>. /// If this is not possible, throws <see cref="NotSupportedException"/>/ /// </summary> /// <typeparam name="TFeature">Type of feature to retrieve.</typeparam> /// <param name="model">Feature model.</param> /// <returns>Feature of type <typeparamref name="TFeature"/>.</returns> /// <exception cref="NotSupportedException">If <paramref name="model"/> doesn't support feature of type <typeparamref name="TFeature"/>.</exception> public static TFeature With <TFeature>(this IFeatureModel model) { Ensure.NotNull(model, "model"); TFeature feature; if (model.TryWith(out feature)) { return(feature); } throw Ensure.Exception.NotSupported( "Feature model '{0}' doesn't support feature '{1}'.", model.GetType().FullName, typeof(TFeature).FullName ); }