Added RedirectUsingNamedRoute
[castle.git] / Core / Castle.Core / Model / InterceptorReference.cs
blobb167fb2fd7760adf346b538578e91dbbfa782559
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
15 namespace Castle.Core
17 using System;
19 public enum InterceptorReferenceType
21 Interface,
22 Key
25 /// <summary>
26 /// Represents an reference to a Interceptor component.
27 /// </summary>
28 [Serializable]
29 public class InterceptorReference : IEquatable<InterceptorReference>
31 private readonly InterceptorReferenceType refType;
32 private readonly Type serviceType;
33 private readonly String componentKey;
35 /// <summary>
36 /// Initializes a new instance of the <see cref="InterceptorReference"/> class.
37 /// </summary>
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;
50 /// <summary>
51 /// Initializes a new instance of the <see cref="InterceptorReference"/> class.
52 /// </summary>
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;
65 /// <summary>
66 /// Gets the type of the service.
67 /// </summary>
68 /// <value>The type of the service.</value>
69 public Type ServiceType
71 get { return serviceType; }
74 /// <summary>
75 /// Gets the interceptor component key.
76 /// </summary>
77 /// <value>The component key.</value>
78 public String ComponentKey
80 get { return componentKey; }
83 /// <summary>
84 /// Gets the type of the reference.
85 /// </summary>
86 /// <value>The type of the reference.</value>
87 public InterceptorReferenceType ReferenceType
89 get { return refType; }
92 /// <summary>
93 /// Gets an <see cref="InterceptorReference"/> for the component key.
94 /// </summary>
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);
102 /// <summary>
103 /// Gets an <see cref="InterceptorReference"/> for the service.
104 /// </summary>
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;
119 return true;
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);
133 return result;