Throw.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #region License
  2. /* Copyright 2013 James F. Bellinger <http://www.zer7.com/software/hidsharp>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  13. #endregion
  14. using System;
  15. using System.Collections.Generic;
  16. namespace HidSharp {
  17. sealed class Throw {
  18. Throw() {
  19. }
  20. public static Throw If {
  21. get { return null; }
  22. }
  23. }
  24. static class ThrowExtensions {
  25. public static Throw Null<T>(this Throw self, T value, string paramName) {
  26. if (value == null) {
  27. throw new ArgumentNullException(paramName);
  28. }
  29. return null;
  30. }
  31. public static Throw OutOfRange<T>(this Throw self, IList<T> buffer, int offset, int count) {
  32. Throw.If.Null(buffer, "buffer");
  33. if (offset < 0 || offset > buffer.Count) {
  34. throw new ArgumentOutOfRangeException("offset");
  35. }
  36. if (count < 0 || count > buffer.Count - offset) {
  37. throw new ArgumentOutOfRangeException("count");
  38. }
  39. return null;
  40. }
  41. }
  42. }