BoxedConstants.cs 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace SmartCoalApplication.Base
  7. {
  8. public sealed class BoxedConstants
  9. {
  10. private static object[] boxedInt32 = new object[1024];
  11. private static object boxedTrue = (object)true;
  12. private static object boxedFalse = (object)false;
  13. public static object GetInt32(int value)
  14. {
  15. if (value >= boxedInt32.Length || value < 0)
  16. {
  17. return (object)value;
  18. }
  19. if (boxedInt32[value] == null)
  20. {
  21. boxedInt32[value] = (object)value;
  22. }
  23. return boxedInt32[value];
  24. }
  25. public static object GetBoolean(bool value)
  26. {
  27. return value ? boxedTrue : boxedFalse;
  28. }
  29. static BoxedConstants()
  30. {
  31. }
  32. private BoxedConstants()
  33. {
  34. }
  35. }
  36. }