/// <inheritdoc />
        public Delegates.ExecuteOperationFunc GetOperationImplementation(string operationName, IEnumerable <string> parameterTypeNames, out IEnumerable <Type> parameterTypes)
        {
            if (operationName == null)
            {
                throw new ArgumentNullException(nameof(operationName));
            }
            if (parameterTypeNames == null)
            {
                throw new ArgumentNullException(nameof(parameterTypeNames));
            }

            // Get the operation implementation (i.e. the specific overload)
            OperationImplementationInfo operationImplementationInfo = this.Operations.GetOperationImplementationInfo(operationName, parameterTypeNames);

            // Return the implementing method
            parameterTypes = operationImplementationInfo.ParameterTypes;
            Delegates.ExecuteOperationFunc implementationFunc = operationImplementationInfo.Implementation(this.ContractImplementation);
            return(implementationFunc);
        }
Esempio n. 2
0
            /// <summary>
            /// Adds information about an operation implementation to this collection.
            /// </summary>
            /// <param name="operationName">The operation's name.</param>
            /// <param name="parameterTypes">The operation's parameter types (order matters).</param>
            /// <param name="getImplementationFunc">A method to get the operation's implementation.</param>
            public void Add(string operationName, IEnumerable <Type> parameterTypes, Delegates.GetExecuteOperationFunc <TContractImplementation> getImplementationFunc)
            {
                if (operationName == null)
                {
                    throw new ArgumentNullException(nameof(operationName));
                }
                if (parameterTypes == null)
                {
                    throw new ArgumentNullException(nameof(parameterTypes));
                }
                if (getImplementationFunc == null)
                {
                    throw new ArgumentNullException(nameof(getImplementationFunc));
                }

                // Add an entry for the operation name if it doesn't exist
                if (!this.OperationImplementationInfos.ContainsKey(operationName))
                {
                    this.OperationImplementationInfos.Add(operationName, new Dictionary <TypeNameList, OperationImplementationInfo>());
                }

                // Get the operation overloads
                IDictionary <TypeNameList, OperationImplementationInfo> overloads = this.OperationImplementationInfos[operationName];

                // Make sure that the overload isn't already defined
                TypeNameList parameterTypeNames = new TypeNameList(parameterTypes); // Should match ParameterValue.TypeCSharpName

                if (overloads.ContainsKey(parameterTypeNames))
                {
                    throw new ArgumentException($"In operation '{operationName}', an overload with the following parameters is already defined: {parameterTypes}");
                }

                // Store the implementation info
                OperationImplementationInfo implementationInfo = new OperationImplementationInfo(operationName, parameterTypes, getImplementationFunc);

                overloads.Add(parameterTypeNames, implementationInfo);
            }