PageRenderTime 116ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/src/sys/dotnet/fan/sys/NullableType.cs

https://bitbucket.org/bedlaczech/fan-1.0
C# | 91 lines | 52 code | 20 blank | 19 comment | 1 complexity | 8fcaa0fb03b0d38c868b7aa9b1ff0d9a MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //
  2. // Copyright (c) 2008, Brian Frank and Andy Frank
  3. // Licensed under the Academic Free License version 3.0
  4. //
  5. // History:
  6. // 21 Oct 08 Andy Frank Creation
  7. //
  8. using System.Runtime.CompilerServices;
  9. namespace Fan.Sys
  10. {
  11. /// <summary>
  12. /// NullableType wraps a type as nullable with trailing "?".
  13. /// </summary>
  14. public class NullableType : Type
  15. {
  16. //////////////////////////////////////////////////////////////////////////
  17. // Constructor
  18. //////////////////////////////////////////////////////////////////////////
  19. internal NullableType(Type root)
  20. {
  21. m_root = root;
  22. m_signature = root.signature() + "?";
  23. }
  24. //////////////////////////////////////////////////////////////////////////
  25. // Type
  26. //////////////////////////////////////////////////////////////////////////
  27. public override int GetHashCode() { return (int)hash(); }
  28. public override long hash() { return m_root.hash() ^ 0x614a9739b1bf9de5L; }
  29. public override bool Equals(object obj)
  30. {
  31. if (obj is NullableType)
  32. {
  33. NullableType x = (NullableType)obj;
  34. return m_root.Equals(x.m_root);
  35. }
  36. return false;
  37. }
  38. public override Pod pod() { return m_root.pod(); }
  39. public override string name() { return m_root.name(); }
  40. public override string qname() { return m_root.qname(); }
  41. public override string signature() { return m_signature; }
  42. internal override int flags() { return m_root.flags(); }
  43. public override Type @base() { return m_root.@base(); }
  44. public override List mixins() { return m_root.mixins(); }
  45. public override List inheritance() { return m_root.inheritance(); }
  46. public override bool @is(Type type) { return m_root.@is(type); }
  47. public override bool isVal() { return m_root.isVal(); }
  48. public override bool isNullable() { return true; }
  49. public override Type toNullable() { return this; }
  50. public override Type toNonNullable() { return m_root; }
  51. public override bool isGenericType() { return m_root.isGenericType(); }
  52. public override bool isGenericInstance() { return m_root.isGenericInstance(); }
  53. public override bool isGenericParameter() { return m_root.isGenericParameter(); }
  54. public override Type getRawType() { return m_root.getRawType(); }
  55. public override Map @params() { return m_root.@params(); }
  56. public override Type parameterize(Map pars) { return m_root.parameterize(pars).toNullable(); }
  57. public override List fields() { return m_root.fields(); }
  58. public override List methods() { return m_root.methods(); }
  59. public override List slots() { return m_root.slots(); }
  60. public override Slot slot(string name, bool check) { return m_root.slot(name, check); }
  61. public override List facets() { return m_root.facets(); }
  62. public override Facet facet(Type t, bool c) { return m_root.facet(t, c); }
  63. public override string doc() { return m_root.doc(); }
  64. public override bool dotnetRepr() { return m_root.dotnetRepr(); }
  65. //////////////////////////////////////////////////////////////////////////
  66. // Fields
  67. //////////////////////////////////////////////////////////////////////////
  68. internal readonly Type m_root;
  69. internal readonly string m_signature;
  70. }
  71. }