1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4 namespace System.ServiceModel.Channels
5 {
6     using System.ServiceModel;
7     using System.ServiceModel.Description;
8     using System.Collections.Generic;
9     internal class DirectionalAction : IComparable<DirectionalAction>
10     {
11         MessageDirection direction;
12         string action;
13         bool isNullAction;
14 
DirectionalAction(MessageDirection direction, string action)15         internal DirectionalAction(MessageDirection direction, string action)
16         {
17             if (!MessageDirectionHelper.IsDefined(direction))
18                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("direction"));
19 
20             this.direction = direction;
21             if (action == null)
22             {
23                 this.action = MessageHeaders.WildcardAction;
24                 this.isNullAction = true;
25             }
26             else
27             {
28                 this.action = action;
29                 this.isNullAction = false;
30             }
31         }
32 
33         public MessageDirection Direction
34         { get { return this.direction; } }
35 
36         public string Action
37         { get { return this.isNullAction ? null : this.action; } }
38 
Equals(Object other)39         public override bool Equals(Object other)
40         {
41             DirectionalAction tmp = other as DirectionalAction;
42             if (tmp == null)
43                 return false;
44             return this.Equals(tmp);
45         }
46 
Equals(DirectionalAction other)47         public bool Equals(DirectionalAction other)
48         {
49             if (other == null)
50                 return false;
51 
52             return (this.direction == other.direction)
53                 && (this.action == other.action);
54         }
55 
CompareTo(DirectionalAction other)56         public int CompareTo(DirectionalAction other)
57         {
58             if (other == null)
59                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other");
60 
61             if ((this.direction == MessageDirection.Input) && (other.direction == MessageDirection.Output))
62                 return -1;
63             if ((this.direction == MessageDirection.Output) && (other.direction == MessageDirection.Input))
64                 return 1;
65 
66             return this.action.CompareTo(other.action);
67         }
68 
GetHashCode()69         public override int GetHashCode()
70         {
71             return this.action.GetHashCode();
72         }
73     }
74 }
75