ConstantHelper.tt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <#@ template debug="true" hostSpecific="true" #>
  2. <#@ output extension=".cs" #>
  3. <#@ Assembly Name="System.Core.dll" #>
  4. <#@ Assembly Name="System.Xml.dll" #>
  5. <#@ Assembly Name="System.Xml.Linq.dll" #>
  6. <#@ Assembly Name="System.Windows.Forms.dll" #>
  7. <#@ import namespace="System" #>
  8. <#@ import namespace="System.IO" #>
  9. <#@ import namespace="System.Diagnostics" #>
  10. <#@ import namespace="System.Linq" #>
  11. <#@ import namespace="System.Xml.Linq" #>
  12. <#@ import namespace="System.Collections" #>
  13. <#@ import namespace="System.Collections.Generic" #>
  14. <#@ import namespace="System.Runtime.InteropServices" #>
  15. <#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
  16. #nullable enable
  17. using System.Runtime.CompilerServices;
  18. namespace System.Numerics
  19. {
  20. internal class ConstantHelper
  21. {
  22. <#
  23. foreach (var type in supportedTypes)
  24. {
  25. string hexValue = "0x" + new string('f', Marshal.SizeOf(type) * 2);
  26. #>
  27. [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
  28. public static <#= typeAliases[type] #> Get<#= type.Name #>WithAllBitsSet()
  29. {
  30. <#= typeAliases[type] #> value = 0;
  31. unsafe
  32. {
  33. unchecked
  34. {
  35. *((<#= typeAliases[GetIntegralEquivalent(type)] #>*)&value) = (<#= typeAliases[GetIntegralEquivalent(type)] #>)<#= hexValue #>;
  36. }
  37. }
  38. return value;
  39. }
  40. <#
  41. }
  42. #>
  43. }
  44. }<#+
  45. public Type GetIntegralEquivalent(Type type)
  46. {
  47. if (type == typeof(float))
  48. {
  49. return typeof(int);
  50. }
  51. else if (type == typeof(double))
  52. {
  53. return typeof(long);
  54. }
  55. else
  56. {
  57. return type;
  58. }
  59. }
  60. #>