ConstantHelper.tt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. using System.Runtime.CompilerServices;
  17. namespace System.Numerics
  18. {
  19. internal class ConstantHelper
  20. {
  21. <#
  22. foreach (var type in supportedTypes)
  23. {
  24. string hexValue = "0x" + new string('f', Marshal.SizeOf(type) * 2);
  25. #>
  26. [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
  27. public static <#= typeAliases[type] #> Get<#= type.Name #>WithAllBitsSet()
  28. {
  29. <#= typeAliases[type] #> value = 0;
  30. unsafe
  31. {
  32. unchecked
  33. {
  34. *((<#= typeAliases[GetIntegralEquivalent(type)] #>*)&value) = (<#= typeAliases[GetIntegralEquivalent(type)] #>)<#= hexValue #>;
  35. }
  36. }
  37. return value;
  38. }
  39. <#
  40. }
  41. #>
  42. }
  43. }<#+
  44. public Type GetIntegralEquivalent(Type type)
  45. {
  46. if (type == typeof(float))
  47. {
  48. return typeof(int);
  49. }
  50. else if (type == typeof(double))
  51. {
  52. return typeof(long);
  53. }
  54. else
  55. {
  56. return type;
  57. }
  58. }
  59. #>