/// <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); }
/// <summary> /// Creates a new <see cref="OperationImplementationInfo" />. /// </summary> /// <param name="operationName">The operation's name.</param> /// <param name="parameterTypes">The type of each parameter.</param> /// <param name="implementation">The implementation of the contract.</param> public OperationImplementationInfo(string operationName, IEnumerable <Type> parameterTypes, Delegates.GetExecuteOperationFunc <TContractImplementation> implementation) { this.OperationName = operationName ?? throw new ArgumentNullException(nameof(operationName)); this.ParameterTypes = parameterTypes ?? Array.Empty <Type>(); this.Implementation = implementation ?? throw new ArgumentNullException(nameof(implementation)); }