ScalarTypes.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. using System.Collections;
  5. using System.Collections.ObjectModel;
  6. namespace OpenXmlPowerTools
  7. {
  8. internal static class DefaultScalarTypes
  9. {
  10. private static readonly Hashtable defaultScalarTypesHash;
  11. internal static bool IsTypeInList(Collection<string> typeNames)
  12. {
  13. string text = PSObjectIsOfExactType(typeNames);
  14. return !string.IsNullOrEmpty(text) && (PSObjectIsEnum(typeNames) || DefaultScalarTypes.defaultScalarTypesHash.ContainsKey(text));
  15. }
  16. static DefaultScalarTypes()
  17. {
  18. DefaultScalarTypes.defaultScalarTypesHash = new Hashtable(StringComparer.OrdinalIgnoreCase);
  19. DefaultScalarTypes.defaultScalarTypesHash.Add("System.String", null);
  20. DefaultScalarTypes.defaultScalarTypesHash.Add("System.SByte", null);
  21. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Byte", null);
  22. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Int16", null);
  23. DefaultScalarTypes.defaultScalarTypesHash.Add("System.UInt16", null);
  24. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Int32", 10);
  25. DefaultScalarTypes.defaultScalarTypesHash.Add("System.UInt32", 10);
  26. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Int64", null);
  27. DefaultScalarTypes.defaultScalarTypesHash.Add("System.UInt64", null);
  28. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Char", 1);
  29. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Single", null);
  30. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Double", null);
  31. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Boolean", 5);
  32. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Decimal", null);
  33. DefaultScalarTypes.defaultScalarTypesHash.Add("System.IntPtr", null);
  34. DefaultScalarTypes.defaultScalarTypesHash.Add("System.Security.SecureString", null);
  35. }
  36. internal static string PSObjectIsOfExactType(Collection<string> typeNames)
  37. {
  38. if (typeNames.Count != 0)
  39. {
  40. return typeNames[0];
  41. }
  42. return null;
  43. }
  44. internal static bool PSObjectIsEnum(Collection<string> typeNames)
  45. {
  46. return typeNames.Count >= 2 && !string.IsNullOrEmpty(typeNames[1]) && string.Equals(typeNames[1], "System.Enum", StringComparison.Ordinal);
  47. }
  48. }
  49. }