OperationContractGenerationContext.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Description
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.CodeDom;
  9. using System.CodeDom.Compiler;
  10. using System.ServiceModel;
  11. public class OperationContractGenerationContext
  12. {
  13. readonly CodeMemberMethod syncMethod;
  14. readonly CodeMemberMethod beginMethod;
  15. readonly ServiceContractGenerationContext contract;
  16. readonly CodeMemberMethod endMethod;
  17. readonly OperationDescription operation;
  18. readonly ServiceContractGenerator serviceContractGenerator;
  19. readonly CodeTypeDeclaration declaringType;
  20. readonly CodeMemberMethod taskMethod;
  21. CodeTypeReference declaringTypeReference;
  22. OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType)
  23. {
  24. if (serviceContractGenerator == null)
  25. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractGenerator"));
  26. if (contract == null)
  27. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contract"));
  28. if (declaringType == null)
  29. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("declaringType"));
  30. this.serviceContractGenerator = serviceContractGenerator;
  31. this.contract = contract;
  32. this.operation = operation;
  33. this.declaringType = declaringType;
  34. }
  35. public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod syncMethod, CodeMemberMethod beginMethod, CodeMemberMethod endMethod, CodeMemberMethod taskMethod)
  36. : this(serviceContractGenerator, contract, operation, declaringType)
  37. {
  38. if (syncMethod == null)
  39. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncMethod"));
  40. if (beginMethod == null)
  41. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("beginMethod"));
  42. if (endMethod == null)
  43. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endMethod"));
  44. if (taskMethod == null)
  45. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("taskMethod"));
  46. this.syncMethod = syncMethod;
  47. this.beginMethod = beginMethod;
  48. this.endMethod = endMethod;
  49. this.taskMethod = taskMethod;
  50. }
  51. public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod syncMethod, CodeMemberMethod beginMethod, CodeMemberMethod endMethod)
  52. : this(serviceContractGenerator, contract, operation, declaringType)
  53. {
  54. if (syncMethod == null)
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncMethod"));
  56. if (beginMethod == null)
  57. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("beginMethod"));
  58. if (endMethod == null)
  59. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endMethod"));
  60. this.syncMethod = syncMethod;
  61. this.beginMethod = beginMethod;
  62. this.endMethod = endMethod;
  63. }
  64. public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod syncMethod, CodeMemberMethod taskMethod)
  65. : this(serviceContractGenerator, contract, operation, declaringType)
  66. {
  67. if (syncMethod == null)
  68. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncMethod"));
  69. if (taskMethod == null)
  70. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("taskMethod"));
  71. this.syncMethod = syncMethod;
  72. this.taskMethod = taskMethod;
  73. }
  74. public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod method)
  75. : this(serviceContractGenerator, contract, operation, declaringType)
  76. {
  77. if (method == null)
  78. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("method"));
  79. this.syncMethod = method;
  80. this.beginMethod = null;
  81. this.endMethod = null;
  82. }
  83. public ServiceContractGenerationContext Contract
  84. {
  85. get { return this.contract; }
  86. }
  87. public CodeTypeDeclaration DeclaringType
  88. {
  89. get { return this.declaringType; }
  90. }
  91. internal CodeTypeReference DeclaringTypeReference
  92. {
  93. get { return this.declaringTypeReference; }
  94. set { this.declaringTypeReference = value; }
  95. }
  96. public CodeMemberMethod BeginMethod
  97. {
  98. get { return this.beginMethod; }
  99. }
  100. public CodeMemberMethod EndMethod
  101. {
  102. get { return this.endMethod; }
  103. }
  104. public CodeMemberMethod TaskMethod
  105. {
  106. get { return this.taskMethod; }
  107. }
  108. public CodeMemberMethod SyncMethod
  109. {
  110. get { return this.syncMethod; }
  111. }
  112. public bool IsAsync
  113. {
  114. get { return this.beginMethod != null; }
  115. }
  116. public bool IsTask
  117. {
  118. get { return this.taskMethod != null; }
  119. }
  120. // true if this operation was declared somewhere up the hierarchy (rather than at this level)
  121. internal bool IsInherited
  122. {
  123. get { return !(this.declaringType == contract.ContractType || this.declaringType == contract.DuplexCallbackType); }
  124. }
  125. public OperationDescription Operation
  126. {
  127. get { return this.operation; }
  128. }
  129. public ServiceContractGenerator ServiceContractGenerator
  130. {
  131. get { return this.serviceContractGenerator; }
  132. }
  133. }
  134. }