/// <summary> /// Throws <see cref="ArgumentOutOfRangeException"/> when <paramref name="key"/> is <see cref="IKey.Empty"/> (= true). /// </summary> /// <param name="condition">The condition helper.</param> /// <param name="key">The to test.</param> public static void NotEmptyKey(this EnsureConditionHelper condition, IKey key) { Ensure.NotNull(condition, "condition"); Ensure.NotNull(key, "key"); if (key.IsEmpty) { throw new RequiredNotEmptyKeyException(key.Type); } }
/// <summary> /// Throws <see cref="ArgumentNullException"/> when <paramref name="xmlFile"/> is <c>null</c> /// and <see cref="FileSystemException"/> when <paramref name="xmlFile"/> is not XML file. /// </summary> /// <param name="condition"></param> /// <param name="xmlFile">File to test.</param> /// <param name="argumentName">File argument name.</param> public static void XmlFile(this EnsureConditionHelper condition, IFile xmlFile, string argumentName) { Ensure.NotNull(condition, "condition"); Ensure.NotNull(xmlFile, argumentName); if (xmlFile.Extension.ToLowerInvariant() != ".xml") { Ensure.Exception.FileSystem("Only xml files are supported, but got file named '{0}{1}'.", xmlFile.Name, xmlFile.Extension); } }
/// <summary> /// Throws <see cref="ArgumentOutOfRangeException"/> when <paramref name="filePath"/> is not existing file. /// Also when <paramref name="filePath"/> is <c>null</c> or <see cref="String.Empty"/>, argument exception are thrown. /// </summary> /// <param name="condition">Ensure condition helper.</param> /// <param name="filePath">File path to test.</param> /// <param name="argumentName">Argument name.</param> public static void FileExists(this EnsureConditionHelper condition, string filePath, string argumentName) { Ensure.NotNull(condition, "condition"); Ensure.NotNullOrEmpty(filePath, "filePath"); if (!File.Exists(filePath)) { throw Ensure.Exception.ArgumentOutOfRange(argumentName, "'{0}' is not existing file.", filePath); } }
/// <summary> /// Throws <see cref="ArgumentOutOfRangeException"/> when <paramref name="directoryPath"/> is not existing directory. /// Also when <paramref name="directoryPath"/> is <c>null</c> or <see cref="String.Empty"/>, argument exception are thrown. /// </summary> /// <param name="condition">Ensure condition helper.</param> /// <param name="directoryPath">Directory path to test.</param> /// <param name="argumentName">Argument name.</param> public static void DirectoryExists(this EnsureConditionHelper condition, string directoryPath, string argumentName) { Ensure.NotNull(condition, "condition"); Ensure.NotNullOrEmpty(directoryPath, "directoryPath"); if (!Directory.Exists(directoryPath)) { throw Ensure.Exception.ArgumentOutOfRange(argumentName, "'{0}' is not existing directory.", directoryPath); } }
/// <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> /// Throws <see cref="ArgumentOutOfRangeException"/> when <paramref name="key"/> has not <paramref name="type"/> as type. /// </summary> /// <param name="condition">The condition helper.</param> /// <param name="key">The to test.</param> /// <param name="type">The required key type.</param> /// <param name="isNotEmptyRequired">Is <c>true</c> only not empty key is accepted</param> public static void NotDifferentKeyType(this EnsureConditionHelper condition, IKey key, string type, bool isNotEmptyRequired = true) { Ensure.NotNull(condition, "condition"); Ensure.NotNull(key, "key"); Ensure.NotNullOrEmpty(type, "type"); if (isNotEmptyRequired) { NotEmptyKey(condition, key); } if (key.Type != type) { throw new RequiredKeyOfTypeException(key.Type, type); } }
public static void NotDifferentKeyType(this EnsureConditionHelper condition, IKey key, string type, string argumentName) { NotDifferentKeyType(condition, key, type, false); }
public static void NotEmptyKey(this EnsureConditionHelper condition, IKey key, string argumentName) { NotEmptyKey(condition, key); }