/// <summary> /// Declare the extension method given the function container class. /// </summary> /// <param name="functionExtensionClass">Function container class</param> /// <param name="func">Function to add</param> protected virtual void DeclareExtensionMethod(CodeTypeDeclaration functionExtensionClass, Function func) { // retrieve parameters and add the extension method ServiceOperationAnnotation actionAnnotation = func.Annotations.OfType <ServiceOperationAnnotation>().Single(); ExceptionUtilities.Assert(actionAnnotation.BindingKind.IsBound(), "Action function cannot generate extension method with out function having a binding"); FunctionParameter bindingTypeParameter = func.Parameters[0]; CodeMemberMethod method = functionExtensionClass.AddExtensionMethod( func.Name, new CodeParameterDeclarationExpression( this.GetParameterTypeOrFunctionReturnTypeReference(bindingTypeParameter.Annotations, bindingTypeParameter.DataType), bindingTypeParameter.Name)); // add non-binding type parameters foreach (var parameter in func.Parameters.Where(p => p.Name != bindingTypeParameter.Name)) { method.Parameters.Add( new CodeParameterDeclarationExpression( this.GetParameterTypeOrFunctionReturnTypeReference(parameter.Annotations, parameter.DataType), parameter.Name)); } // throw exception if the client code method is called method.Statements.Add( new CodeThrowExceptionStatement( new CodeObjectCreateExpression( new CodeTypeReference(typeof(InvalidOperationException)), new CodeExpression[] { }))); // add method return type if (func.ReturnType != null) { method.ReturnType = this.GetParameterTypeOrFunctionReturnTypeReference(func.Annotations, func.ReturnType); } }