Added RedirectUsingNamedRoute
[castle.git] / InversionOfControl / Castle.MicroKernel / Proxy / ProxyOptions.cs
blob77b421bba9b63dad52567fe892dead549d138ac1
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.MicroKernel.Proxy
17 using System;
18 using System.Collections;
20 /// <summary>
21 /// Represents options to configure proxies.
22 /// </summary>
23 public class ProxyOptions
25 private IProxyHook hook;
26 private ArrayList interfaceList;
27 private bool useSingleInterfaceProxy;
28 private bool useMarshalByRefAsBaseClass;
29 private bool omitTarget;
31 /// <summary>
32 /// Initializes a new instance of the <see cref="ProxyOptions"/> class.
33 /// </summary>
34 public ProxyOptions()
36 useSingleInterfaceProxy = false;
37 omitTarget = false;
40 /// <summary>
41 /// Gets or sets the proxy hook.
42 /// </summary>
43 public IProxyHook Hook
45 get { return hook; }
46 set { hook = value; }
49 /// <summary>
50 /// Determines if the proxied component uses a target.
51 /// </summary>
52 public bool OmitTarget
54 get { return omitTarget; }
55 set { omitTarget = value; }
58 /// <summary>
59 /// Determines if the proxied component should only include
60 /// the service interface.
61 /// </summary>
62 public bool UseSingleInterfaceProxy
64 get { return useSingleInterfaceProxy; }
65 set { useSingleInterfaceProxy = value; }
68 /// <summary>
69 /// Determines if the interface proxied component should inherit
70 /// from <see cref="MarshalByRefObject"/>
71 /// </summary>
72 public bool UseMarshalByRefAsBaseClass
74 get { return useMarshalByRefAsBaseClass; }
75 set { useMarshalByRefAsBaseClass = value; }
78 /// <summary>
79 /// Gets the additional interfaces to proxy.
80 /// </summary>
81 /// <value>The interfaces.</value>
82 public Type[] AdditionalInterfaces
84 get
86 if (interfaceList != null)
88 return (Type[]) interfaceList.ToArray(typeof(Type));
91 return new Type[0];
95 /// <summary>
96 /// Adds the additional interfaces to proxy.
97 /// </summary>
98 /// <param name="interfaces">The interfaces.</param>
99 public void AddAdditionalInterfaces(params Type[] interfaces)
101 if (interfaces == null)
103 throw new ArgumentNullException("interfaces");
106 if (interfaceList == null)
108 interfaceList = new ArrayList();
111 interfaceList.AddRange(interfaces);
114 /// <summary>
115 /// Equalses the specified obj.
116 /// </summary>
117 /// <param name="obj">The obj.</param>
118 /// <returns>true if equal.</returns>
119 public override bool Equals(object obj)
121 if (this == obj) return true;
122 ProxyOptions proxyOptions = obj as ProxyOptions;
123 if (proxyOptions == null) return false;
124 if (!Equals(hook, proxyOptions.hook)) return false;
125 if (!Equals(useSingleInterfaceProxy, proxyOptions.useSingleInterfaceProxy)) return false;
126 if (!Equals(omitTarget, proxyOptions.omitTarget)) return false;
127 return AdditionalInterfacesAreEquals(proxyOptions);
130 /// <summary>
131 /// Gets the hash code.
132 /// </summary>
133 /// <returns></returns>
134 public override int GetHashCode()
136 return 29 * base.GetHashCode() + GetAdditionalInterfacesHashCode();
139 private bool AdditionalInterfacesAreEquals(ProxyOptions proxyOptions)
141 if (!Equals(interfaceList == null, proxyOptions.interfaceList == null)) return false;
142 if (interfaceList == null) return true; //both are null, nothing more to check
143 if (interfaceList.Count != proxyOptions.interfaceList.Count) return false;
144 for(int i = 0; i < interfaceList.Count; ++i)
146 if (!proxyOptions.interfaceList.Contains(interfaceList[0])) return false;
148 return true;
151 private int GetAdditionalInterfacesHashCode()
153 int result = 0;
155 if (interfaceList == null) return result;
157 foreach(object type in interfaceList)
159 result = 29 * result + type.GetHashCode();
162 return result;