IsAssignableAndNotTransparentProxy() public static méthode

Checks whether the supplied instance is not a transparent proxy and is assignable to the supplied type.

Neccessary when dealing with server-activated remote objects, because the object is of the type TransparentProxy and regular is testing for assignable types does not work.

Transparent proxy instances always return when tested with the 'is' operator (C#). This method only checks if the object is assignable to the type if it is not a transparent proxy.

public static IsAssignableAndNotTransparentProxy ( Type type, object instance ) : bool
type System.Type The target to be checked.
instance object The value that should be assigned to the type.
Résultat bool
Exemple #1
0
        public void IsAssignableAndNotTransparentProxyWithProxy()
        {
            AppDomain domain = null;

            try
            {
                AppDomainSetup setup = new AppDomainSetup();
                setup.ApplicationBase = Environment.CurrentDirectory;
                domain = AppDomain.CreateDomain("Spring", new Evidence(AppDomain.CurrentDomain.Evidence), setup);
                object foo = domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(Foo).FullName);
                // the instance is definitely assignable to the supplied interface type...
                bool isAssignable = ObjectUtils.IsAssignableAndNotTransparentProxy(typeof(IFoo), foo);
                Assert.IsFalse(isAssignable, "Proxied instance was not recognized as such.");
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }