Fixing an issue with output parameters that are of type IntPtr
[castle.git] / InversionOfControl / Castle.MicroKernel / Proxy / ProxyOptions.cs
blobdd41838f23e2ae8914b91511c75b6b0e6304d6ad
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 allowChangeTarget;
30 private bool omitTarget;
32 /// <summary>
33 /// Initializes a new instance of the <see cref="ProxyOptions"/> class.
34 /// </summary>
35 public ProxyOptions()
37 useSingleInterfaceProxy = false;
38 omitTarget = false;
41 /// <summary>
42 /// Gets or sets the proxy hook.
43 /// </summary>
44 public IProxyHook Hook
46 get { return hook; }
47 set { hook = value; }
50 /// <summary>
51 /// Determines if the proxied component uses a target.
52 /// </summary>
53 public bool OmitTarget
55 get { return omitTarget; }
56 set { omitTarget = value; }
59 /// <summary>
60 /// Determines if the proxied component can change targets.
61 /// </summary>
62 public bool AllowChangeTarget
64 get { return allowChangeTarget; }
65 set { allowChangeTarget = value; }
68 /// <summary>
69 /// Determines if the proxied component should only include
70 /// the service interface.
71 /// </summary>
72 public bool UseSingleInterfaceProxy
74 get { return useSingleInterfaceProxy; }
75 set { useSingleInterfaceProxy = value; }
78 /// <summary>
79 /// Determines if the interface proxied component should inherit
80 /// from <see cref="MarshalByRefObject"/>
81 /// </summary>
82 public bool UseMarshalByRefAsBaseClass
84 get { return useMarshalByRefAsBaseClass; }
85 set { useMarshalByRefAsBaseClass = value; }
88 /// <summary>
89 /// Gets the additional interfaces to proxy.
90 /// </summary>
91 /// <value>The interfaces.</value>
92 public Type[] AdditionalInterfaces
94 get
96 if (interfaceList != null)
98 return (Type[]) interfaceList.ToArray(typeof(Type));
101 return new Type[0];
105 /// <summary>
106 /// Adds the additional interfaces to proxy.
107 /// </summary>
108 /// <param name="interfaces">The interfaces.</param>
109 public void AddAdditionalInterfaces(params Type[] interfaces)
111 if (interfaces == null)
113 throw new ArgumentNullException("interfaces");
116 if (interfaceList == null)
118 interfaceList = new ArrayList();
121 interfaceList.AddRange(interfaces);
124 /// <summary>
125 /// Equalses the specified obj.
126 /// </summary>
127 /// <param name="obj">The obj.</param>
128 /// <returns>true if equal.</returns>
129 public override bool Equals(object obj)
131 if (this == obj) return true;
132 ProxyOptions proxyOptions = obj as ProxyOptions;
133 if (proxyOptions == null) return false;
134 if (!Equals(hook, proxyOptions.hook)) return false;
135 if (!Equals(useSingleInterfaceProxy, proxyOptions.useSingleInterfaceProxy)) return false;
136 if (!Equals(omitTarget, proxyOptions.omitTarget)) return false;
137 return AdditionalInterfacesAreEquals(proxyOptions);
140 /// <summary>
141 /// Gets the hash code.
142 /// </summary>
143 /// <returns></returns>
144 public override int GetHashCode()
146 return 29 * base.GetHashCode() + GetAdditionalInterfacesHashCode();
149 private bool AdditionalInterfacesAreEquals(ProxyOptions proxyOptions)
151 if (!Equals(interfaceList == null, proxyOptions.interfaceList == null)) return false;
152 if (interfaceList == null) return true; //both are null, nothing more to check
153 if (interfaceList.Count != proxyOptions.interfaceList.Count) return false;
154 for(int i = 0; i < interfaceList.Count; ++i)
156 if (!proxyOptions.interfaceList.Contains(interfaceList[0])) return false;
158 return true;
161 private int GetAdditionalInterfacesHashCode()
163 int result = 0;
165 if (interfaceList == null) return result;
167 foreach(object type in interfaceList)
169 result = 29 * result + type.GetHashCode();
172 return result;