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
ForType(Type service
)
109 return new InterceptorReference(service
);
113 /// Gets an <see cref="InterceptorReference"/> for the service.
115 /// <typeparam name="T">The service type.</typeparam>
116 /// <returns>The <see cref="InterceptorReference"/></returns>
117 public static InterceptorReference ForType
<T
>()
119 return new InterceptorReference(typeof(T
));
122 public bool Equals(InterceptorReference interceptorReference
)
124 if (interceptorReference
== null) return false;
125 if (!Equals(refType
, interceptorReference
.refType
)) return false;
126 if (!Equals(serviceType
, interceptorReference
.serviceType
)) return false;
127 if (!Equals(componentKey
, interceptorReference
.componentKey
)) return false;
131 public override bool Equals(object obj
)
133 if (ReferenceEquals(this, obj
)) return true;
134 return Equals(obj
as InterceptorReference
);
137 public override int GetHashCode()
139 int result
= refType
.GetHashCode();
140 result
= 29*result
+ (serviceType
!= null ? serviceType
.GetHashCode() : 0);
141 result
= 29*result
+ (componentKey
!= null ? componentKey
.GetHashCode() : 0);