Esempio n. 1
0
        ///<summary>
        /// checks, whether <paramref name="target"/> supports the methods of <paramref name="requiredType"/>.
        /// Supports testing transparent proxies.
        ///</summary>
        ///<param name="target">the target instance or <c>null</c></param>
        ///<param name="targetName">the name of the target to be used in error messages</param>
        ///<param name="requiredType">the type to test for</param>
        /// <exception cref="ArgumentNullException">
        /// if <paramref name="requiredType"/> is <c>null</c>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// if it is not possible to invoke methods of
        /// type <paramref name="requiredType"/> on <paramref name="target"/>
        /// </exception>
        public static void Understands(object target, string targetName, Type requiredType)
        {
            ArgumentNotNull(requiredType, "requiredType");

            if (target == null)
            {
                ThrowNotSupportedException($"Target '{targetName}' is null.");
            }

            Type targetType = null;

            if (RemotingServices.IsTransparentProxy(target))
            {
#if !NETSTANDARD
                System.Runtime.Remoting.Proxies.RealProxy rp = RemotingServices.GetRealProxy(target);
                IRemotingTypeInfo rti = rp as IRemotingTypeInfo;
                if (rti != null)
                {
                    if (rti.CanCastTo(requiredType, target))
                    {
                        return;
                    }
                    ThrowNotSupportedException(
                        $"Target '{targetName}' is a transparent proxy that does not support methods of '{requiredType.FullName}'.");
                }
                targetType = rp.GetProxiedType();
#endif
            }
            else
            {
                targetType = target.GetType();
            }

            if (!requiredType.IsAssignableFrom(targetType))
            {
                ThrowNotSupportedException($"Target '{targetName}' of type '{targetType}' does not support methods of '{requiredType.FullName}'.");
            }
        }
 public static Object GetStubData(System.Runtime.Remoting.Proxies.RealProxy rp)
 {
     return(default(Object));
 }
 public static void SetStubData(System.Runtime.Remoting.Proxies.RealProxy rp, Object stubData)
 {
 }
Esempio n. 4
0
 public static void SwitchWrappers(System.Runtime.Remoting.Proxies.RealProxy oldcp, System.Runtime.Remoting.Proxies.RealProxy newcp)
 {
 }
 public static void SwitchWrappers(System.Runtime.Remoting.Proxies.RealProxy oldcp, System.Runtime.Remoting.Proxies.RealProxy newcp)
 {
     Contract.Requires(newcp != null);
     Contract.Requires(oldcp != null);
 }