/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
namespace dnSpy.Contracts.Debugger.DotNet.Evaluation {
///
/// Return value of methods creating s
///
public readonly struct DbgDotNetValueResult {
///
/// Gets the value or null if there was an error ().
/// If is true, this is the thrown exception value.
///
public DbgDotNetValue? Value { get; }
///
/// true if contains the thrown exception instead of the expected return value / field value
///
public bool ValueIsException { get; }
///
/// Gets the error message or null if there was no error
///
public string? ErrorMessage { get; }
///
/// true if there was an error, see
///
public bool HasError => ErrorMessage is not null;
///
/// true if there's no error and no exception was thrown
///
public bool IsNormalResult => !HasError && !ValueIsException;
///
/// Creates a normal result
///
/// Value
///
public static DbgDotNetValueResult Create(DbgDotNetValue value) =>
new DbgDotNetValueResult(value, valueIsException: false);
///
/// Creates an exception result
///
/// Exception value
///
public static DbgDotNetValueResult CreateException(DbgDotNetValue value) =>
new DbgDotNetValueResult(value, valueIsException: true);
///
/// Creates an error result
///
/// Error message
///
public static DbgDotNetValueResult CreateError(string errorMessage) =>
new DbgDotNetValueResult(errorMessage);
DbgDotNetValueResult(DbgDotNetValue value, bool valueIsException) {
Value = value ?? throw new ArgumentNullException(nameof(value));
ValueIsException = valueIsException;
ErrorMessage = null;
}
DbgDotNetValueResult(string errorMessage) {
Value = null;
ValueIsException = false;
ErrorMessage = errorMessage ?? throw new ArgumentNullException(nameof(errorMessage));
}
}
}