/Mono.Cecil/FunctionPointerType.cs

http://github.com/jbevain/cecil · C# · 111 lines · 81 code · 21 blank · 9 comment · 0 complexity · 1e366e6fb27053f4acaf0be44d198366 MD5 · raw file

  1. //
  2. // Author:
  3. // Jb Evain (jbevain@gmail.com)
  4. //
  5. // Copyright (c) 2008 - 2015 Jb Evain
  6. // Copyright (c) 2008 - 2011 Novell, Inc.
  7. //
  8. // Licensed under the MIT/X11 license.
  9. //
  10. using System;
  11. using System.Text;
  12. using Mono.Collections.Generic;
  13. using MD = Mono.Cecil.Metadata;
  14. namespace Mono.Cecil {
  15. public sealed class FunctionPointerType : TypeSpecification, IMethodSignature {
  16. readonly MethodReference function;
  17. public bool HasThis {
  18. get { return function.HasThis; }
  19. set { function.HasThis = value; }
  20. }
  21. public bool ExplicitThis {
  22. get { return function.ExplicitThis; }
  23. set { function.ExplicitThis = value; }
  24. }
  25. public MethodCallingConvention CallingConvention {
  26. get { return function.CallingConvention; }
  27. set { function.CallingConvention = value; }
  28. }
  29. public bool HasParameters {
  30. get { return function.HasParameters; }
  31. }
  32. public Collection<ParameterDefinition> Parameters {
  33. get { return function.Parameters; }
  34. }
  35. public TypeReference ReturnType {
  36. get { return function.MethodReturnType.ReturnType; }
  37. set { function.MethodReturnType.ReturnType = value; }
  38. }
  39. public MethodReturnType MethodReturnType {
  40. get { return function.MethodReturnType; }
  41. }
  42. public override string Name {
  43. get { return function.Name; }
  44. set { throw new InvalidOperationException (); }
  45. }
  46. public override string Namespace {
  47. get { return string.Empty; }
  48. set { throw new InvalidOperationException (); }
  49. }
  50. public override ModuleDefinition Module {
  51. get { return ReturnType.Module; }
  52. }
  53. public override IMetadataScope Scope {
  54. get { return function.ReturnType.Scope; }
  55. set { throw new InvalidOperationException (); }
  56. }
  57. public override bool IsFunctionPointer {
  58. get { return true; }
  59. }
  60. public override bool ContainsGenericParameter {
  61. get { return function.ContainsGenericParameter; }
  62. }
  63. public override string FullName {
  64. get {
  65. var signature = new StringBuilder ();
  66. signature.Append (function.Name);
  67. signature.Append (" ");
  68. signature.Append (function.ReturnType.FullName);
  69. signature.Append (" *");
  70. this.MethodSignatureFullName (signature);
  71. return signature.ToString ();
  72. }
  73. }
  74. public FunctionPointerType ()
  75. : base (null)
  76. {
  77. this.function = new MethodReference ();
  78. this.function.Name = "method";
  79. this.etype = MD.ElementType.FnPtr;
  80. }
  81. public override TypeDefinition Resolve ()
  82. {
  83. return null;
  84. }
  85. public override TypeReference GetElementType ()
  86. {
  87. return this;
  88. }
  89. }
  90. }