IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext) 方法
定义
实现此方法可以在开始协定生成过程之前修改代码文档对象模型。Implement to modify the code document object model prior to the contract generation process.
public:
void GenerateContract(System::ServiceModel::Description::ServiceContractGenerationContext ^ context);
public void GenerateContract (System.ServiceModel.Description.ServiceContractGenerationContext context);
abstract member GenerateContract : System.ServiceModel.Description.ServiceContractGenerationContext -> unit
Public Sub GenerateContract (context As ServiceContractGenerationContext)
参数
- context
- ServiceContractGenerationContext
代码生成要使用的上下文,以在生成之前修改代码文档。The code generated context to use to modify the code document prior to generation.
示例
下面的代码示例演示了如何在调用 IServiceContractGenerationExtension 期间向 ContractDescription.Behaviors 属性添加 ImportContract。The following code example shows how to add an IServiceContractGenerationExtension to the ContractDescription.Behaviors property during the call to ImportContract.
public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
{
Console.Write("ImportContract");
// Contract Documentation
if (context.WsdlPortType.Documentation != null)
{
context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.Documentation));
}
// Operation Documentation
foreach (Operation operation in context.WsdlPortType.Operations)
{
if (operation.Documentation != null)
{
OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
if (operationDescription != null)
{
operationDescription.Behaviors.Add(new WsdlDocumentationImporter(operation.Documentation));
}
}
}
}
下面的代码示例演示了向为服务协定生成的代码中添加注释的 GenerateContract 的实现。The following code examples show the implementation of GenerateContract that adds comments to the code generated for a service contract.
public void GenerateContract(ServiceContractGenerationContext context)
{
Console.WriteLine("In generate contract.");
context.ContractType.Comments.AddRange(Formatter.FormatComments(commentText));
}
下面的代码示例演示了对服务协定生成的注释。The following code example shows the generated comments on the service contract.
/// From WSDL Documentation:
///
/// <summary>The string for the Name data member.</summary>
///
[System.Runtime.Serialization.DataMemberAttribute()]
public string Name
{
get
{
return this.NameField;
}
set
{
this.NameField = value;
}
}
'''From WSDL Documentation:
'''
'''<summary>The string for the Name data member.</summary>
'''
<System.Runtime.Serialization.DataMemberAttribute()> _
Public Property Name() As String
Get
Return Me.NameField
End Get
Set
Me.NameField = value
End Set
End Property
注解
使用 System.ServiceModel.Description.ServiceContractGenerationContext 在代码生成之前修改协定、操作或 System.ServiceModel.Description.ServiceContractGenerator。Use the System.ServiceModel.Description.ServiceContractGenerationContext to modify the contract, operations, or the System.ServiceModel.Description.ServiceContractGenerator prior to code generation.