Пример #1
0
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            ComProxy proxy3;

            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }
            if (this.contractType == null)
            {
                TypeCacheManager.Provider.FindOrCreateType(riid, out this.contractType, true, false);
            }
            if ((this.contractType.GUID != riid) && !this.CheckDispatch(ref riid))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(System.ServiceModel.SR.GetString("NoInterface", new object[] { (Guid)riid })));
            }
            System.Type  proxiedType = EmitterCache.TypeEmitter.FindOrCreateType(this.contractType);
            ComProxy     proxy       = null;
            TearOffProxy disp        = null;

            try
            {
                disp   = new TearOffProxy(this, proxiedType);
                proxy  = ComProxy.Create(outer, disp.GetTransparentProxy(), disp);
                proxy3 = proxy;
            }
            finally
            {
                if ((proxy == null) && (disp != null))
                {
                    ((IDisposable)disp).Dispose();
                }
            }
            return(proxy3);
        }
Пример #2
0
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }

            // No contract Fault on in
            if (contractType == null)
            {
                TypeCacheManager.Provider.FindOrCreateType(riid, out contractType, true, false);
            }

            if ((contractType.GUID != riid) && !(CheckDispatch(ref riid)))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));
            }

            Type         proxiedType  = EmitterCache.TypeEmitter.FindOrCreateType(contractType);
            ComProxy     comProxy     = null;
            TearOffProxy tearoffProxy = null;

            try
            {
                tearoffProxy = new TearOffProxy(this, proxiedType);
                comProxy     = ComProxy.Create(outer, tearoffProxy.GetTransparentProxy(), tearoffProxy);
                return(comProxy);
            }
            finally
            {
                if ((comProxy == null) && (tearoffProxy != null))
                {
                    ((IDisposable)tearoffProxy).Dispose();
                }
            }
        }
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }

            // No contract Fault on in
            if (contractType == null)
                TypeCacheManager.Provider.FindOrCreateType(riid, out contractType, true, false);

            if ((contractType.GUID != riid) && !(CheckDispatch(ref riid)))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));

            Type proxiedType = EmitterCache.TypeEmitter.FindOrCreateType(contractType);
            ComProxy comProxy = null;
            TearOffProxy tearoffProxy = null;
            try
            {
                tearoffProxy = new TearOffProxy(this, proxiedType);
                comProxy = ComProxy.Create(outer, tearoffProxy.GetTransparentProxy(), tearoffProxy);
                return comProxy;

            }
            finally
            {
                if ((comProxy == null) && (tearoffProxy != null))
                    ((IDisposable)tearoffProxy).Dispose();

            }
        }