<commit_before>﻿using System;
using System.AddIn.Contract;
using RedGate.AppHost.Interfaces;

namespace RedGate.AppHost.Server
{
    internal class AppHostChildHandle : IAppHostChildHandle
    {
        private readonly ISafeAppHostChildHandle m_SafeAppHostChildHandle;

        public AppHostChildHandle(ISafeAppHostChildHandle safeAppHostChildHandle)
        {
            m_SafeAppHostChildHandle = safeAppHostChildHandle;
        }

        public INativeHandleContract Initialize(IAppHostServices services)
        {
            var nativeHandleContractWithoutIntPtr = m_SafeAppHostChildHandle.Initialize(services);

            return new NativeHandleContractAdapter(nativeHandleContractWithoutIntPtr);
        }

        private class NativeHandleContractAdapter : INativeHandleContract
        {
            private readonly INativeHandleContractWithoutIntPtr m_Upstream;

            internal NativeHandleContractAdapter(INativeHandleContractWithoutIntPtr upstream)
            {
                if (upstream == null)
                {
                    throw new ArgumentNullException("upstream");
                }
                m_Upstream = upstream;
            }


            public IContract QueryContract(string contractIdentifier)
            {
                return m_Upstream.QueryContract(contractIdentifier);
            }

            public int GetRemoteHashCode()
            {
                return m_Upstream.GetRemoteHashCode();
            }

            public bool RemoteEquals(IContract contract)
            {
                return m_Upstream.RemoteEquals(contract);
            }

            public string RemoteToString()
            {
                return m_Upstream.RemoteToString();
            }

            public int AcquireLifetimeToken()
            {
                return m_Upstream.AcquireLifetimeToken();
            }

            public void RevokeLifetimeToken(int token)
            {
                m_Upstream.RevokeLifetimeToken(token);
            }

            public IntPtr GetHandle()
            {
                return (IntPtr)m_Upstream.GetHandle();
            }
        }
    }
}<commit_msg>Getting a weird invalidcastexception when trying to integrate. Why<commit_after>﻿using System;
using System.AddIn.Contract;
using RedGate.AppHost.Interfaces;

namespace RedGate.AppHost.Server
{
    internal class AppHostChildHandle : IAppHostChildHandle
    {
        private readonly ISafeAppHostChildHandle m_SafeAppHostChildHandle;

        public AppHostChildHandle(ISafeAppHostChildHandle safeAppHostChildHandle)
        {
            m_SafeAppHostChildHandle = safeAppHostChildHandle;
        }

        public INativeHandleContract Initialize(IAppHostServices services)
        {
            object handleContractWithoutIntPtr = m_SafeAppHostChildHandle.Initialize(services);
            
            INativeHandleContractWithoutIntPtr nativeHandleContractWithoutIntPtr = (INativeHandleContractWithoutIntPtr) handleContractWithoutIntPtr;

            return new NativeHandleContractAdapter(nativeHandleContractWithoutIntPtr);
        }

        private class NativeHandleContractAdapter : INativeHandleContract
        {
            private readonly INativeHandleContractWithoutIntPtr m_Upstream;

            internal NativeHandleContractAdapter(INativeHandleContractWithoutIntPtr upstream)
            {
                if (upstream == null)
                {
                    throw new ArgumentNullException("upstream");
                }
                m_Upstream = upstream;
            }


            public IContract QueryContract(string contractIdentifier)
            {
                return m_Upstream.QueryContract(contractIdentifier);
            }

            public int GetRemoteHashCode()
            {
                return m_Upstream.GetRemoteHashCode();
            }

            public bool RemoteEquals(IContract contract)
            {
                return m_Upstream.RemoteEquals(contract);
            }

            public string RemoteToString()
            {
                return m_Upstream.RemoteToString();
            }

            public int AcquireLifetimeToken()
            {
                return m_Upstream.AcquireLifetimeToken();
            }

            public void RevokeLifetimeToken(int token)
            {
                m_Upstream.RevokeLifetimeToken(token);
            }

            public IntPtr GetHandle()
            {
                return (IntPtr)m_Upstream.GetHandle();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.050489987217724755, 'fraction_numerical': 0.0, 'mean_word_length': 1.7138728323699421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7381429', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1028, 'n_words': 186}