Added RedirectUsingNamedRoute
[castle.git] / InversionOfControl / Castle.MicroKernel / Proxy / ProxyUtil.cs
blob2956ba9f1f3f6a375fd8858d3ed4300c1be0e0aa
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.Runtime.Remoting;
18 using Castle.Core;
19 using Castle.Core.Interceptor;
21 /// <summary>
22 /// Helper support for proxy configuration.
23 /// </summary>
24 public abstract class ProxyUtil
26 /// <summary>
27 /// Obtains the <see cref="ProxyOptions"/> associated with the <see cref="ComponentModel"/>.
28 /// </summary>
29 /// <param name="model">The component model.</param>
30 /// <param name="createOnDemand">true if the options should be created if not present.</param>
31 /// <returns>The associated proxy options for the component model.</returns>
32 public static ProxyOptions ObtainProxyOptions(ComponentModel model, bool createOnDemand)
34 ProxyOptions options = model.ExtendedProperties[ProxyConstants.ProxyOptionsKey] as ProxyOptions;
36 if (options == null && createOnDemand)
38 options = new ProxyOptions();
39 model.ExtendedProperties[ProxyConstants.ProxyOptionsKey] = options;
42 return options;
45 public static object GetUnproxiedInstance(object instance)
47 if (!RemotingServices.IsTransparentProxy(instance))
49 IProxyTargetAccessor accessor = instance as IProxyTargetAccessor;
51 if (accessor != null)
53 instance = accessor.DynProxyGetTarget();
57 return instance;