// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc.Formatters
{
///
/// Result of a operation.
///
public class InputFormatterResult
{
private static readonly InputFormatterResult _failure = new InputFormatterResult();
private static readonly Task _failureAsync = Task.FromResult(_failure);
private InputFormatterResult()
{
HasError = true;
}
private InputFormatterResult(object model)
{
Model = model;
}
///
/// Gets an indication whether the operation had an error.
///
public bool HasError { get; }
///
/// Gets the deserialized .
///
///
/// null if is true.
///
public object Model { get; }
///
/// Returns an indicating the
/// operation failed.
///
///
/// An indicating the
/// operation failed i.e. with true.
///
public static InputFormatterResult Failure()
{
return _failure;
}
///
/// Returns a that on completion provides an indicating
/// the operation failed.
///
///
/// A that on completion provides an indicating the
/// operation failed i.e. with true.
///
public static Task FailureAsync()
{
return _failureAsync;
}
///
/// Returns an indicating the
/// operation was successful.
///
/// The deserialized .
///
/// An indicating the
/// operation succeeded i.e. with false.
///
public static InputFormatterResult Success(object model)
{
return new InputFormatterResult(model);
}
///
/// Returns a that on completion provides an indicating
/// the operation was successful.
///
/// The deserialized .
///
/// A that on completion provides an indicating the
/// operation succeeded i.e. with false.
///
public static Task SuccessAsync(object model)
{
return Task.FromResult(Success(model));
}
}
}