/// <summary>
        /// Loads all methods from interfaces and assigns an identifier
        /// to each. These are later synchronized with the client.
        /// </summary>
        private void CreateMethodMap()
        {
            _serviceInstance = new ServiceInstance()
            {
                KeyIndex = 0, //only one per intercepted interface
                InterfaceType = _serviceType,
                InterfaceMethods = new ConcurrentDictionary<int, MethodInfo>(),
                MethodParametersByRef = new ConcurrentDictionary<int, bool[]>(),
                SingletonInstance = _interceptPoint.Target
            };

            var currentMethodIdent = 0;
            if (_serviceType.IsInterface)
            {
                var methodInfos = _serviceType.GetMethods();
                foreach (var mi in methodInfos)
                {
                    _serviceInstance.InterfaceMethods.TryAdd(currentMethodIdent, mi);
                    var parameterInfos = mi.GetParameters();
                    var isByRef = new bool[parameterInfos.Length];
                    for (int i = 0; i < isByRef.Length; i++)
                        isByRef[i] = parameterInfos[i].ParameterType.IsByRef;
                    _serviceInstance.MethodParametersByRef.TryAdd(currentMethodIdent, isByRef);
                    currentMethodIdent++;
                }
            }

            var interfaces = _serviceType.GetInterfaces();
            foreach (var interfaceType in interfaces)
            {
                var methodInfos = interfaceType.GetMethods();
                foreach (var mi in methodInfos)
                {
                    _serviceInstance.InterfaceMethods.TryAdd(currentMethodIdent, mi);
                    var parameterInfos = mi.GetParameters();
                    var isByRef = new bool[parameterInfos.Length];
                    for (int i = 0; i < isByRef.Length; i++)
                        isByRef[i] = parameterInfos[i].ParameterType.IsByRef;
                    _serviceInstance.MethodParametersByRef.TryAdd(currentMethodIdent, isByRef);
                    currentMethodIdent++;
                }
            }

            //Create a list of sync infos from the dictionary
            var syncSyncInfos = new List<MethodSyncInfo>();
            foreach (var kvp in _serviceInstance.InterfaceMethods)
            {
                var parameters = kvp.Value.GetParameters();
                var parameterTypes = new Type[parameters.Length];
                for (var i = 0; i < parameters.Length; i++)
                    parameterTypes[i] = parameters[i].ParameterType;
                syncSyncInfos.Add(new MethodSyncInfo
                {
                    MethodIdent = kvp.Key,
                    MethodName = kvp.Value.Name,
                    ParameterTypes = parameterTypes
                });
            }

            var serviceSyncInfo = new ServiceSyncInfo
            {
                ServiceKeyIndex = 0,
                CompressionThreshold = 131072,
                UseCompression = false,
                MethodInfos = syncSyncInfos.ToArray()
            };
            _serviceInstance.ServiceSyncInfo = serviceSyncInfo;
        }
        /// <summary>
        /// Loads all methods from interfaces and assigns an identifier
        /// to each. These are later synchronized with the client.
        /// </summary>
        private void CreateMethodMap()
        {
            _serviceInstance = new ServiceInstance()
            {
                KeyIndex              = 0, //only one per intercepted interface
                InterfaceType         = _serviceType,
                InterfaceMethods      = new ConcurrentDictionary <int, MethodInfo>(),
                MethodParametersByRef = new ConcurrentDictionary <int, bool[]>(),
                SingletonInstance     = _interceptPoint.Target
            };

            var currentMethodIdent = 0;

            if (_serviceType.IsInterface())
            {
                var methodInfos = _serviceType.GetMethods();
                foreach (var mi in methodInfos)
                {
                    _serviceInstance.InterfaceMethods.TryAdd(currentMethodIdent, mi);
                    var parameterInfos = mi.GetParameters();
                    var isByRef        = new bool[parameterInfos.Length];
                    for (int i = 0; i < isByRef.Length; i++)
                    {
                        isByRef[i] = parameterInfos[i].ParameterType.IsByRef;
                    }
                    _serviceInstance.MethodParametersByRef.TryAdd(currentMethodIdent, isByRef);
                    currentMethodIdent++;
                }
            }

            var interfaces = _serviceType.GetInterfaces();

            foreach (var interfaceType in interfaces)
            {
                var methodInfos = interfaceType.GetMethods();
                foreach (var mi in methodInfos)
                {
                    _serviceInstance.InterfaceMethods.TryAdd(currentMethodIdent, mi);
                    var parameterInfos = mi.GetParameters();
                    var isByRef        = new bool[parameterInfos.Length];
                    for (int i = 0; i < isByRef.Length; i++)
                    {
                        isByRef[i] = parameterInfos[i].ParameterType.IsByRef;
                    }
                    _serviceInstance.MethodParametersByRef.TryAdd(currentMethodIdent, isByRef);
                    currentMethodIdent++;
                }
            }


            //Create a list of sync infos from the dictionary
            var syncSyncInfos = new List <MethodSyncInfo>();

            foreach (var kvp in _serviceInstance.InterfaceMethods)
            {
                var parameters     = kvp.Value.GetParameters();
                var parameterTypes = new Type[parameters.Length];
                for (var i = 0; i < parameters.Length; i++)
                {
                    parameterTypes[i] = parameters[i].ParameterType;
                }
                syncSyncInfos.Add(new MethodSyncInfo
                {
                    MethodIdent    = kvp.Key,
                    MethodName     = kvp.Value.Name,
                    ParameterTypes = parameterTypes
                });
            }

            var serviceSyncInfo = new ServiceSyncInfo
            {
                ServiceKeyIndex      = 0,
                CompressionThreshold = 131072,
                UseCompression       = false,
                MethodInfos          = syncSyncInfos.ToArray()
            };

            _serviceInstance.ServiceSyncInfo = serviceSyncInfo;
        }