1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
19 public enum InterceptorReferenceType
26 /// Represents an reference to a Interceptor component.
29 public class InterceptorReference
: IEquatable
<InterceptorReference
>
31 private readonly InterceptorReferenceType refType
;
32 private readonly Type serviceType
;
33 private readonly String componentKey
;
36 /// Initializes a new instance of the <see cref="InterceptorReference"/> class.
38 /// <param name="componentKey">The component key.</param>
39 public InterceptorReference(String componentKey
)
41 if (componentKey
== null)
43 throw new ArgumentNullException("componentKey cannot be null");
46 refType
= InterceptorReferenceType
.Key
;
47 this.componentKey
= componentKey
;
51 /// Initializes a new instance of the <see cref="InterceptorReference"/> class.
53 /// <param name="serviceType">Type of the service.</param>
54 public InterceptorReference(Type serviceType
)
56 if (serviceType
== null)
58 throw new ArgumentNullException("'serviceType' cannot be null");
61 refType
= InterceptorReferenceType
.Interface
;
62 this.serviceType
= serviceType
;
66 /// Gets the type of the service.
68 /// <value>The type of the service.</value>
69 public Type ServiceType
71 get { return serviceType; }
75 /// Gets the interceptor component key.
77 /// <value>The component key.</value>
78 public String ComponentKey
80 get { return componentKey; }
84 /// Gets the type of the reference.
86 /// <value>The type of the reference.</value>
87 public InterceptorReferenceType ReferenceType
89 get { return refType; }
93 /// Gets an <see cref="InterceptorReference"/> for the component key.
95 /// <param name="key">The component key.</param>
96 /// <returns>The <see cref="InterceptorReference"/></returns>
97 public static InterceptorReference
ForKey(String key
)
99 return new InterceptorReference(key
);
103 /// Gets an <see cref="InterceptorReference"/> for the service.
105 /// <param name="service">The service.</param>
106 /// <returns>The <see cref="InterceptorReference"/></returns>
107 public static InterceptorReference
WithType(Type service
)
109 return new InterceptorReference(service
);
113 public bool Equals(InterceptorReference interceptorReference
)
115 if (interceptorReference
== null) return false;
116 if (!Equals(refType
, interceptorReference
.refType
)) return false;
117 if (!Equals(serviceType
, interceptorReference
.serviceType
)) return false;
118 if (!Equals(componentKey
, interceptorReference
.componentKey
)) return false;
122 public override bool Equals(object obj
)
124 if (ReferenceEquals(this, obj
)) return true;
125 return Equals(obj
as InterceptorReference
);
128 public override int GetHashCode()
130 int result
= refType
.GetHashCode();
131 result
= 29*result
+ (serviceType
!= null ? serviceType
.GetHashCode() : 0);
132 result
= 29*result
+ (componentKey
!= null ? componentKey
.GetHashCode() : 0);