Range.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //------------------------------------------------------------------------------
  2. // <copyright file="Range.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. // <owner current="false" primary="false">[....]</owner>
  8. //------------------------------------------------------------------------------
  9. namespace System.Data {
  10. using System;
  11. internal struct Range {
  12. private int min;
  13. private int max;
  14. private bool isNotNull; // zero bit pattern represents null
  15. public Range(int min, int max) {
  16. if (min > max) {
  17. throw ExceptionBuilder.RangeArgument(min, max);
  18. }
  19. this.min = min;
  20. this.max = max;
  21. isNotNull = true;
  22. }
  23. public int Count {
  24. get {
  25. if (IsNull)
  26. return 0;
  27. return max - min + 1;
  28. }
  29. }
  30. public bool IsNull {
  31. get {
  32. return !isNotNull;
  33. }
  34. }
  35. public int Max {
  36. get {
  37. CheckNull();
  38. return max;
  39. }
  40. }
  41. public int Min {
  42. get {
  43. CheckNull();
  44. return min;
  45. }
  46. }
  47. internal void CheckNull() {
  48. if (this.IsNull) {
  49. throw ExceptionBuilder.NullRange();
  50. }
  51. }
  52. }
  53. }