Few name changes and expose AdditionalParameters in CreationContext.
[castle.git] / Core / Castle.Core / Model / InterceptorReference.cs
blob5753bf111fb66ad4dc32e2a1fb9ece7a40bb5aaf
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 ForType(Type service)
109 return new InterceptorReference(service);
112 /// <summary>
113 /// Gets an <see cref="InterceptorReference"/> for the service.
114 /// </summary>
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;
128 return true;
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);
142 return result;