Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Dispatcher / OperationInvokerBehavior.cs
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //-----------------------------------------------------------------------------
4
5 namespace System.ServiceModel.Dispatcher
6 {
7     using System.Collections.Generic;
8     using System.ServiceModel.Channels;
9     using System.ServiceModel.Description;
10
11     class OperationInvokerBehavior : IOperationBehavior
12     {
13         public OperationInvokerBehavior()
14         {
15         }
16
17         void IOperationBehavior.Validate(OperationDescription description)
18         {
19         }
20
21         void IOperationBehavior.AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
22         {
23         }
24
25         void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
26         {
27             if (dispatch == null)
28             {
29                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatch");
30             }
31             if (description == null)
32             {
33                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
34             }
35
36             if (description.TaskMethod != null)
37             {
38                 dispatch.Invoker = new TaskMethodInvoker(description.TaskMethod, description.TaskTResult);
39             }
40             else if (description.SyncMethod != null)
41             {
42                 if (description.BeginMethod != null)
43                 {
44                     // both sync and async methods are present on the contract, check the preference
45                     OperationBehaviorAttribute operationBehaviorAttribue = description.Behaviors.Find<OperationBehaviorAttribute>();
46                     if ((operationBehaviorAttribue != null) && operationBehaviorAttribue.PreferAsyncInvocation)
47                     {
48                         dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
49                     }
50                     else
51                     {
52                         dispatch.Invoker = new SyncMethodInvoker(description.SyncMethod);
53                     }
54                 }
55                 else
56                 {
57                     // only sync method is present on the contract
58                     dispatch.Invoker = new SyncMethodInvoker(description.SyncMethod);
59                 }
60             }
61             else
62             {
63                 if (description.BeginMethod != null)
64                 {
65                     // only async method is present on the contract
66                     dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
67                 }
68             }
69         }
70
71         void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
72         {
73         }
74     }
75 }