示例#1
0
        internal static T?TryGetManagedObject <T>(IComWrapperFixed comWrapper) where T : class
        {
            if (comWrapper == null)
            {
                return(null);
            }

            var handle = GCHandle.FromIntPtr(comWrapper.GCHandlePtr);

            return(handle.Target as T);
        }
示例#2
0
        internal static T GetManagedObject <T>(IComWrapperFixed comWrapper) where T : class
        {
            Contract.ThrowIfNull(comWrapper, "comWrapper");

            var handle = GCHandle.FromIntPtr(comWrapper.GCHandlePtr);
            var target = handle.Target;

            Contract.ThrowIfNull(target, "target");
            Debug.Assert(target is T, "Why are you casting an object to an reference type it doesn't support?");
            return((T)target);
        }