/*
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;
using System.Collections.ObjectModel;
namespace dnSpy.Contracts.Debugger.Exceptions {
///
/// Exception settings service
///
public abstract class DbgExceptionSettingsService {
///
/// Resets all exception settings and removes user-added exceptions
///
public abstract void Reset();
///
/// Modifies an existing exception. It raises if the
/// new settings are not equal to the current settings.
///
/// Id of existing exception
/// New settings
public void Modify(DbgExceptionId id, DbgExceptionSettings settings) =>
Modify(new[] { new DbgExceptionIdAndSettings(id, settings) });
///
/// Modifies existing exceptions. It raises if the
/// new settings are not equal to the current settings.
///
/// New settings
public abstract void Modify(DbgExceptionIdAndSettings[] settings);
///
/// Raised when an exception is modified
///
public abstract event EventHandler? ExceptionSettingsModified;
///
/// Removes exception settings
///
/// IDs of all exceptions to remove
public abstract void Remove(DbgExceptionId[] ids);
///
/// Adds an exception
///
/// Exception settings
public void Add(in DbgExceptionSettingsInfo settings) => Add(new[] { settings });
///
/// Adds exceptions
///
/// Exception settings
public abstract void Add(DbgExceptionSettingsInfo[] settings);
///
/// Gets all exceptions
///
public abstract DbgExceptionSettingsInfo[] Exceptions { get; }
///
/// Raised when is changed
///
public abstract event EventHandler>? ExceptionsChanged;
///
/// Returns the exception definition if it exists
///
/// Exception id
/// Updated with the exception definition if the method returns true
///
public abstract bool TryGetDefinition(DbgExceptionId id, out DbgExceptionDefinition definition);
///
/// Returns exception settings or false if the exception doesn't exist in the collection
///
/// Id of exception
/// Updated with the exception settings if the method returns true
///
public abstract bool TryGetSettings(DbgExceptionId id, out DbgExceptionSettings settings);
///
/// Returns exception settings. If the exception doesn't exist in the collection, the default exception settings is returned
///
/// Id of exception
///
public abstract DbgExceptionSettings GetSettings(DbgExceptionId id);
///
/// Gets the category definition if it exists
///
/// Category, see
/// Updated with the category definition if the method returns true
///
public abstract bool TryGetCategoryDefinition(string category, out DbgExceptionCategoryDefinition definition);
///
/// Gets all category definitions
///
public abstract ReadOnlyCollection CategoryDefinitions { get; }
}
///
/// Contains the exception definition and exception settings
///
public readonly struct DbgExceptionSettingsInfo {
///
/// Gets the definition
///
public DbgExceptionDefinition Definition { get; }
///
/// Gets the settings
///
public DbgExceptionSettings Settings { get; }
///
/// Constructor
///
/// Exception definition
/// Exception settings
public DbgExceptionSettingsInfo(DbgExceptionDefinition definition, DbgExceptionSettings settings) {
if (definition.Id.Category is null)
throw new ArgumentException();
if (settings.Conditions is null)
throw new ArgumentException();
Definition = definition;
Settings = settings;
}
}
///
/// Exception id and settings
///
public readonly struct DbgExceptionIdAndSettings {
///
/// Gets the exception id
///
public DbgExceptionId Id { get; }
///
/// Gets the settings
///
public DbgExceptionSettings Settings { get; }
///
/// Constructor
///
/// Exception id
/// Settings
public DbgExceptionIdAndSettings(DbgExceptionId id, DbgExceptionSettings settings) {
if (id.Category is null)
throw new ArgumentException();
if (settings.Conditions is null)
throw new ArgumentException();
Id = id;
Settings = settings;
}
}
///
/// event args
///
public readonly struct DbgExceptionSettingsModifiedEventArgs {
///
/// Gets the ID and new settings
///
public ReadOnlyCollection IdAndSettings { get; }
///
/// Constructor
///
/// New settings
public DbgExceptionSettingsModifiedEventArgs(ReadOnlyCollection idAndSettings) =>
IdAndSettings = idAndSettings ?? throw new ArgumentNullException(nameof(idAndSettings));
}
}