1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
;
19 using Castle
.Core
.Interceptor
;
22 /// Helper support for proxy configuration.
24 public abstract class ProxyUtil
27 /// Obtains the <see cref="ProxyOptions"/> associated with the <see cref="ComponentModel"/>.
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
;
45 public static object GetUnproxiedInstance(object instance
)
47 if (!RemotingServices
.IsTransparentProxy(instance
))
49 IProxyTargetAccessor accessor
= instance
as IProxyTargetAccessor
;
53 instance
= accessor
.DynProxyGetTarget();