private async Task WriteOperationParameterAsync(ODataParameterWriter parameterWriter, IEdmOperationParameter operationParameter, string paramName, object paramValue) { switch (operationParameter.Type.Definition.TypeKind) { case EdmTypeKind.Primitive: case EdmTypeKind.Complex: var value = GetPropertyValue(operationParameter.Type, paramValue); await parameterWriter.WriteValueAsync(paramName, value).ConfigureAwait(false); break; case EdmTypeKind.Enum: await parameterWriter.WriteValueAsync(paramName, new ODataEnumValue(paramValue.ToString())).ConfigureAwait(false); break; case EdmTypeKind.Entity: var entryWriter = await parameterWriter.CreateEntryWriterAsync(paramName).ConfigureAwait(false); var entry = CreateODataEntry(operationParameter.Type.Definition.FullTypeName(), paramValue.ToDictionary()); await entryWriter.WriteStartAsync(entry).ConfigureAwait(false); await entryWriter.WriteEndAsync().ConfigureAwait(false); break; case EdmTypeKind.Collection: var collectionType = operationParameter.Type.Definition as IEdmCollectionType; var elementType = collectionType.ElementType; if (elementType.Definition.TypeKind == EdmTypeKind.Entity) { var feedWriter = await parameterWriter.CreateFeedWriterAsync(paramName).ConfigureAwait(false); var feed = new ODataFeed(); await feedWriter.WriteStartAsync(feed).ConfigureAwait(false); foreach (var item in paramValue as IEnumerable) { var feedEntry = CreateODataEntry(elementType.Definition.FullTypeName(), item.ToDictionary()); await feedWriter.WriteStartAsync(feedEntry).ConfigureAwait(false); await feedWriter.WriteEndAsync().ConfigureAwait(false); } await feedWriter.WriteEndAsync().ConfigureAwait(false); } else { var collectionWriter = await parameterWriter.CreateCollectionWriterAsync(paramName).ConfigureAwait(false); await collectionWriter.WriteStartAsync(new ODataCollectionStart()).ConfigureAwait(false); foreach (var item in paramValue as IEnumerable) { await collectionWriter.WriteItemAsync(item).ConfigureAwait(false); } await collectionWriter.WriteEndAsync().ConfigureAwait(false); } break; default: throw new NotSupportedException(string.Format("Unable to write action parameter of a type {0}", operationParameter.Type.Definition.TypeKind)); } }