📜  orElseThrow - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:50.047000             🧑  作者: Mango

代码示例1
private static  HttpMessageWriter findWriter(
    BodyInserter.Context context, ResolvableType elementType, @Nullable MediaType mediaType) {
  return context.messageWriters().stream()
      .filter(messageWriter -> messageWriter.canWrite(elementType, mediaType))
      .findFirst()
      .map(BodyInserters::cast)
      .orElseThrow(() -> new IllegalStateException(
          "No HttpMessageWriter for \"" + mediaType + "\" and \"" + elementType + "\""));
}