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.
31 public class InterceptorReference
: IEquatable
<InterceptorReference
>
33 private readonly InterceptorReferenceType refType
;
34 private readonly Type serviceType
;
35 private readonly String componentKey
;
38 /// Initializes a new instance of the <see cref="InterceptorReference"/> class.
40 /// <param name="componentKey">The component key.</param>
41 public InterceptorReference(String componentKey
)
43 if (componentKey
== null)
45 throw new ArgumentNullException("componentKey cannot be null");
48 refType
= InterceptorReferenceType
.Key
;
49 this.componentKey
= componentKey
;
53 /// Initializes a new instance of the <see cref="InterceptorReference"/> class.
55 /// <param name="serviceType">Type of the service.</param>
56 public InterceptorReference(Type serviceType
)
58 if (serviceType
== null)
60 throw new ArgumentNullException("'serviceType' cannot be null");
63 refType
= InterceptorReferenceType
.Interface
;
64 this.serviceType
= serviceType
;
68 /// Gets the type of the service.
70 /// <value>The type of the service.</value>
71 public Type ServiceType
73 get { return serviceType; }
77 /// Gets the interceptor component key.
79 /// <value>The component key.</value>
80 public String ComponentKey
82 get { return componentKey; }
86 /// Gets the type of the reference.
88 /// <value>The type of the reference.</value>
89 public InterceptorReferenceType ReferenceType
91 get { return refType; }
95 /// Gets an <see cref="InterceptorReference"/> for the component key.
97 /// <param name="key">The component key.</param>
98 /// <returns>The <see cref="InterceptorReference"/></returns>
99 public static InterceptorReference
ForKey(String key
)
101 return new InterceptorReference(key
);
105 /// Gets an <see cref="InterceptorReference"/> for the service.
107 /// <param name="service">The service.</param>
108 /// <returns>The <see cref="InterceptorReference"/></returns>
109 public static InterceptorReference
ForType(Type service
)
111 return new InterceptorReference(service
);
115 /// Gets an <see cref="InterceptorReference"/> for the service.
117 /// <typeparam name="T">The service type.</typeparam>
118 /// <returns>The <see cref="InterceptorReference"/></returns>
119 public static InterceptorReference ForType
<T
>()
121 return new InterceptorReference(typeof(T
));
124 public bool Equals(InterceptorReference interceptorReference
)
126 if (interceptorReference
== null) return false;
127 if (!Equals(refType
, interceptorReference
.refType
)) return false;
128 if (!Equals(serviceType
, interceptorReference
.serviceType
)) return false;
129 if (!Equals(componentKey
, interceptorReference
.componentKey
)) return false;
133 public override bool Equals(object obj
)
135 if (ReferenceEquals(this, obj
)) return true;
136 return Equals(obj
as InterceptorReference
);
139 public override int GetHashCode()
141 int result
= refType
.GetHashCode();
142 result
= 29*result
+ (serviceType
!= null ? serviceType
.GetHashCode() : 0);
143 result
= 29*result
+ (componentKey
!= null ? componentKey
.GetHashCode() : 0);