Added container accessor to Castle.Core
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy / Generators / CacheKey.cs
blob74c81b0341893eea95fc7b4872da4c73510e7309
1 // Copyright 2004-2007 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.DynamicProxy.Generators
17 using System;
19 public class CacheKey
21 private readonly Type targetType;
22 private readonly Type[] interfaces;
23 private readonly ProxyGenerationOptions options;
24 private readonly Type proxyForType;
26 /// <summary>
27 /// Initializes a new instance of the <see cref="CacheKey"/> class.
28 /// </summary>
29 /// <param name="targetType">Type of the target.</param>
30 /// <param name="interfaces">The interfaces.</param>
31 /// <param name="options">The options.</param>
32 public CacheKey(Type targetType, Type[] interfaces, ProxyGenerationOptions options)
34 this.targetType = targetType;
35 this.interfaces = interfaces;
36 this.options = options;
39 public CacheKey(Type proxyForType, Type targetType, Type[] interfaces, ProxyGenerationOptions options)
40 : this(targetType, interfaces, options)
42 this.proxyForType = proxyForType;
45 public override int GetHashCode()
47 int result = targetType.GetHashCode();
48 if (interfaces != null)
50 foreach(Type inter in interfaces)
52 result += 29 + inter.GetHashCode();
55 result = 29 * result + options.GetHashCode();
56 if (proxyForType != null)
57 result = 29*result + proxyForType.GetHashCode();
58 return result;
61 public override bool Equals(object obj)
63 if (this == obj) return true;
64 CacheKey cacheKey = obj as CacheKey;
65 if (cacheKey == null) return false;
66 if (proxyForType != null && !Equals(proxyForType, cacheKey.proxyForType)) return false;
67 if (!Equals(targetType, cacheKey.targetType)) return false;
68 if (interfaces != null && cacheKey.interfaces == null) return false;
69 if (interfaces == null && cacheKey.interfaces != null) return false;
70 if (interfaces != null && interfaces.Length != cacheKey.interfaces.Length) return false;
71 if (interfaces != null)
73 for(int i = 0; i < interfaces.Length; i++)
75 if (!Equals(interfaces[i], cacheKey.interfaces[i])) return false;
78 if (!Equals(options, cacheKey.options)) return false;
79 return true;