コード例 #1
0
 /// <summary>
 /// Wraps the given instance in a proxy with interception hooked up if it
 /// is required by policy. If not required, returns the unwrapped instance.
 /// </summary>
 /// <param name="instance">object to wrap.</param>
 /// <param name="typeToReturn">Type of the reference to return.</param>
 /// <param name="policiesForThisType">Policy set specific to typeToReturn.</param>
 /// <returns>The object with policy added.</returns>
 protected override object DoWrap(object instance, Type typeToReturn, PolicySet policiesForThisType)
 {
     if (PolicyRequiresInterception(policiesForThisType))
     {
         InterceptingRealProxy proxy =
             new InterceptingRealProxy(UnwrapTarget(instance), typeToReturn, policiesForThisType);
         return(proxy.GetTransparentProxy());
     }
     return(instance);
 }
コード例 #2
0
 private object UnwrapTarget(object target)
 {
     if (RemotingServices.IsTransparentProxy(target))
     {
         InterceptingRealProxy realProxy =
             RemotingServices.GetRealProxy(target) as InterceptingRealProxy;
         if (realProxy != null)
         {
             return(realProxy.Target);
         }
     }
     return(target);
 }