- Timestamp:
- 07/05/13 10:50:47 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Data Path DataTypes/HeuristicLab.Data/3.3/Path Types/PathValue.cs
r9680 r9697 21 21 22 22 23 using System;24 23 using System.IO; 25 24 using HeuristicLab.Common; … … 31 30 [StorableClass] 32 31 public abstract class PathValue : StringValue { 33 [Storable]34 private bool checkExistence;35 public bool CheckExistence {36 get { return checkExistence; }37 set {38 if (ReadOnly) throw new NotSupportedException("CheckExistence cannot be set. PathValue is read-only.");39 if (value != checkExistence) {40 checkExistence = value;41 OnCheckExistenceChanged();42 }43 }44 }45 46 32 public override string Value { 47 33 get { return base.Value; } 48 34 set { 49 35 if (value == null) value = string.Empty; 50 if (checkExistence && !string.IsNullOrEmpty(value) && !File.Exists(value) && !Directory.Exists(value)) 51 throw new ArgumentException(string.Format("The given file {0} does not exists.", value)); 52 if (value[value.Length - 1] == Path.DirectorySeparatorChar) 53 value = value.TrimEnd(Path.DirectorySeparatorChar); 54 if (value[value.Length - 1] == Path.AltDirectorySeparatorChar) 55 value = value.TrimEnd(Path.AltDirectorySeparatorChar); 36 value = value.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); 56 37 base.Value = value; 57 38 } … … 60 41 [StorableConstructor] 61 42 protected PathValue(bool deserializing) : base(deserializing) { } 62 protected PathValue(PathValue original, Cloner cloner) 63 : base(original, cloner) { 64 checkExistence = original.checkExistence; 65 } 43 protected PathValue(PathValue original, Cloner cloner) : base(original, cloner) { } 66 44 67 45 protected PathValue() 68 : base(string.Empty) { 69 checkExistence = true; 70 } 46 : base(string.Empty) { } 71 47 72 48 public abstract bool Exists(); 73 74 protected override bool Validate(string value, out string errorMessage) {75 if (CheckExistence && !File.Exists(value) && !Directory.Exists(value)) {76 errorMessage = string.Format("The given path {0} does not exist.", value);77 return false;78 }79 return base.Validate(value, out errorMessage);80 }81 82 public event EventHandler CheckExistenceChanged;83 protected virtual void OnCheckExistenceChanged() {84 var handler = CheckExistenceChanged;85 if (handler != null)86 handler(this, EventArgs.Empty);87 }88 49 } 89 50 }
Note: See TracChangeset
for help on using the changeset viewer.