1 using System; 2 using System.Collections.Generic; 3 4 namespace Lextm.SharpSnmpLib.Mib 5 { 6 public class ValueRanges: List<ValueRange> 7 { 8 public bool IsSizeDeclaration { get; internal set; } 9 ValueRanges(bool isSizeDecl = false)10 public ValueRanges(bool isSizeDecl = false) 11 { 12 IsSizeDeclaration = isSizeDecl; 13 } 14 Contains(Int64 value)15 public bool Contains(Int64 value) 16 { 17 foreach (ValueRange range in this) 18 { 19 if (range.Contains(value)) 20 { 21 return true; 22 } 23 } 24 25 return false; 26 } 27 } 28 29 public class ValueRange 30 { 31 private readonly Int64 _start; 32 private readonly Int64? _end; 33 ValueRange(Int64 first, Int64? second)34 public ValueRange(Int64 first, Int64? second) 35 { 36 _start = first; 37 _end = second; 38 } 39 40 public Int64 Start 41 { 42 get { return _start; } 43 } 44 45 public Int64? End 46 { 47 get { return _end; } 48 } 49 IntersectsWith(ValueRange other)50 public bool IntersectsWith(ValueRange other) 51 { 52 if (this._end == null) 53 { 54 return other.Contains(this._start); 55 } 56 else if (other._end == null) 57 { 58 return this.Contains(other._start); 59 } 60 61 return (this._start <= other.End) && (this._end >= other._start); 62 } 63 Contains(Int64 value)64 public bool Contains(Int64 value) 65 { 66 if (_end == null) 67 { 68 return value == _start; 69 } 70 else 71 { 72 return (_start <= value) && (value <= _end); 73 } 74 } 75 } 76 } 77