public Task ExtendModelAsync( ModelContext context, CancellationToken cancellationToken) { var model = context.Model; var entityContainer = model.EntityContainer as EdmEntityContainer; foreach (ActionMethodInfo actionInfo in this.ActionInfos) { var returnTypeReference = ConventionalActionProvider.GetReturnTypeReference(actionInfo.Method.ReturnType); var action = new EdmAction(entityContainer.Namespace, actionInfo.ActionName, returnTypeReference); foreach (ParameterInfo parameter in actionInfo.Method.GetParameters()) { EdmOperationParameter actionParam = new EdmOperationParameter( action, parameter.Name, ConventionalActionProvider.GetTypeReference(parameter.ParameterType)); action.AddParameter(actionParam); } model.AddElement(action); if (!action.IsBound) { EdmActionImport actionImport = new EdmActionImport(entityContainer, action.Name, action); entityContainer.AddElement(actionImport); } } return(Task.FromResult <object>(null)); }
private static EdmTypeReference GetReturnTypeReference(Type type) { if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Task <>)) { // if the action returns a Task<T>, map that to just be returning a T type = type.GetGenericArguments()[0]; } else if (type == typeof(Task)) { // if the action returns a concrete Task, map that to being a void return type. type = typeof(void); } return(ConventionalActionProvider.GetTypeReference(type)); }