Added container accessor to Castle.Core
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy / ProxyGenerationOptions.cs
blobee7061d62866c64e3a6674914be7ebbf6df5496d
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
17 using System;
18 using System.Collections;
19 using System.Runtime.Serialization;
21 [Serializable]
22 public class ProxyGenerationOptions : ISerializable
24 public static readonly ProxyGenerationOptions Default = new ProxyGenerationOptions();
26 private IProxyGenerationHook hook;
27 private IInterceptorSelector selector;
28 private ArrayList mixins;
29 private Type baseTypeForInterfaceProxy = typeof(object);
30 private bool useSingleInterfaceProxy;
31 private bool useSelector;
33 /// <summary>
34 /// Initializes a new instance of the <see cref="ProxyGenerationOptions"/> class.
35 /// </summary>
36 /// <param name="hook">The hook.</param>
37 public ProxyGenerationOptions(IProxyGenerationHook hook)
39 this.hook = hook;
40 useSelector = false;
43 /// <summary>
44 /// Initializes a new instance of the <see cref="ProxyGenerationOptions"/> class.
45 /// </summary>
46 public ProxyGenerationOptions() : this(new AllMethodsHook())
50 private ProxyGenerationOptions (SerializationInfo info, StreamingContext context)
52 hook = (IProxyGenerationHook) info.GetValue ("hook", typeof (IProxyGenerationHook));
53 selector = (IInterceptorSelector) info.GetValue ("selector", typeof (IInterceptorSelector));
54 mixins = (ArrayList) info.GetValue ("mixins", typeof (ArrayList));
55 baseTypeForInterfaceProxy = Type.GetType (info.GetString ("baseTypeForInterfaceProxy.AssemblyQualifiedName"));
56 useSingleInterfaceProxy = info.GetBoolean ("useSingleInterfaceProxy");
57 useSelector = info.GetBoolean ("useSelector");
60 public void GetObjectData (SerializationInfo info, StreamingContext context)
62 info.AddValue ("hook", hook);
63 info.AddValue ("selector", selector);
64 info.AddValue ("mixins", mixins);
65 info.AddValue ("baseTypeForInterfaceProxy.AssemblyQualifiedName", baseTypeForInterfaceProxy.AssemblyQualifiedName);
66 info.AddValue ("useSingleInterfaceProxy", useSingleInterfaceProxy);
67 info.AddValue ("useSelector", useSelector);
70 public IProxyGenerationHook Hook
72 get { return hook; }
73 set { hook = value; }
76 public IInterceptorSelector Selector
78 get { return selector; }
79 set { selector = value; }
82 public bool UseSelector
84 get { return useSelector; }
85 set { useSelector = value; }
88 public bool UseSingleInterfaceProxy
90 get { return useSingleInterfaceProxy; }
91 set { useSingleInterfaceProxy = value; }
94 public void AddMixinInstance(object instance)
96 if (instance == null)
98 throw new ArgumentNullException("instance");
101 if (mixins == null)
103 mixins = new ArrayList();
106 mixins.Add(instance);
109 public object[] MixinsAsArray()
111 if (mixins == null) return new object[0];
113 return mixins.ToArray();
116 public bool HasMixins
118 get { return mixins == null ? false : mixins.Count != 0; }
121 public Type BaseTypeForInterfaceProxy
123 get { return baseTypeForInterfaceProxy; }
124 set { baseTypeForInterfaceProxy = value; }
127 public override bool Equals(object obj)
129 if (this == obj) return true;
130 ProxyGenerationOptions proxyGenerationOptions = obj as ProxyGenerationOptions;
131 if (proxyGenerationOptions == null) return false;
132 if (!Equals(hook.GetType(), proxyGenerationOptions.hook.GetType())) return false;
133 if (!Equals(selector, proxyGenerationOptions.selector)) return false;
134 if (!Equals(mixins, proxyGenerationOptions.mixins)) return false;
135 if (!Equals(baseTypeForInterfaceProxy, proxyGenerationOptions.baseTypeForInterfaceProxy)) return false;
136 if (!Equals(useSelector, proxyGenerationOptions.useSelector)) return false;
137 if (!Equals(useSingleInterfaceProxy, proxyGenerationOptions.useSingleInterfaceProxy)) return false;
138 return true;
141 public override int GetHashCode()
143 int result = hook != null ? hook.GetType().GetHashCode() : 0;
144 result = 29 * result + (selector != null ? selector.GetHashCode() : 0);
145 result = 29 * result + (mixins != null ? mixins.GetHashCode() : 0);
146 result = 29 * result + (baseTypeForInterfaceProxy != null ? baseTypeForInterfaceProxy.GetHashCode() : 0);
147 result = 29 * result + useSelector.GetHashCode();
148 result = 29 * result + useSingleInterfaceProxy.GetHashCode();
149 return result;