/*
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;
using System.ComponentModel.Composition;
using dnSpy.Contracts.Debugger.DotNet.Text;
using dnSpy.Contracts.Debugger.Evaluation;
using dnSpy.Debugger.DotNet.Metadata;
namespace dnSpy.Contracts.Debugger.DotNet.Evaluation.ValueNodes {
///
/// Creates value nodes. Use
/// to export an instance.
///
public abstract class DbgDotNetValueNodeFactory {
///
/// Creates a value node
///
/// Evaluation info
/// Name
/// Value
/// Format specifiers or null
/// Options
/// Expression
/// Image name, see
/// true if it's a read-only value
/// true if the expression causes side effects
/// Expected type
///
public abstract DbgDotNetValueNode Create(DbgEvaluationInfo evalInfo, DbgDotNetText name, DbgDotNetValue value, ReadOnlyCollection? formatSpecifiers, DbgValueNodeEvaluationOptions options, string expression, string imageName, bool isReadOnly, bool causesSideEffects, DmdType expectedType);
///
/// Creates an exception value node
///
/// Evaluation info
/// Exception id
/// Value
/// Format specifiers or null
/// Options
///
public abstract DbgDotNetValueNode CreateException(DbgEvaluationInfo evalInfo, uint id, DbgDotNetValue value, ReadOnlyCollection? formatSpecifiers, DbgValueNodeEvaluationOptions options);
///
/// Creates an exception value node
///
/// Evaluation info
/// Stowed exception id
/// Value
/// Format specifiers or null
/// Options
///
public abstract DbgDotNetValueNode CreateStowedException(DbgEvaluationInfo evalInfo, uint id, DbgDotNetValue value, ReadOnlyCollection? formatSpecifiers, DbgValueNodeEvaluationOptions options);
///
/// Creates a return value node
///
/// Evaluation info
/// Return value id
/// Value
/// Format specifiers or null
/// Options
/// Method
///
public abstract DbgDotNetValueNode CreateReturnValue(DbgEvaluationInfo evalInfo, uint id, DbgDotNetValue value, ReadOnlyCollection? formatSpecifiers, DbgValueNodeEvaluationOptions options, DmdMethodBase method);
///
/// Creates an error value node
///
/// Evaluation info
/// Name
/// Error message
/// Expression
/// true if the expression causes side effects
///
public abstract DbgDotNetValueNode CreateError(DbgEvaluationInfo evalInfo, DbgDotNetText name, string errorMessage, string expression, bool causesSideEffects);
///
/// Creates type variables value node
///
/// Evaluation info
/// Type variables
///
public abstract DbgDotNetValueNode CreateTypeVariables(DbgEvaluationInfo evalInfo, DbgDotNetTypeVariableInfo[] typeVariableInfos);
}
/// Metadata
public interface IDbgDotNetValueNodeFactoryMetadata {
/// See
string LanguageGuid { get; }
/// See
double Order { get; }
}
///
/// Exports a instance
///
[MetadataAttribute, AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class ExportDbgDotNetValueNodeFactoryAttribute : ExportAttribute, IDbgDotNetValueNodeFactoryMetadata {
///
/// Constructor
///
/// Language GUID, see
/// Order
public ExportDbgDotNetValueNodeFactoryAttribute(string languageGuid, double order = double.MaxValue)
: base(typeof(DbgDotNetValueNodeFactory)) {
LanguageGuid = languageGuid ?? throw new ArgumentNullException(nameof(languageGuid));
Order = order;
}
///
/// Language GUID, see
///
public string LanguageGuid { get; }
///
/// Order
///
public double Order { get; }
}
///
/// Contains the generic parameter and type
///
public readonly struct DbgDotNetTypeVariableInfo {
///
/// Gets the generic parameter type
///
public DmdType GenericParameterType { get; }
///
/// Gets the generic argument type
///
public DmdType GenericArgumentType { get; }
///
/// Constructor
///
/// Generic parameter type
/// Generic argument type
public DbgDotNetTypeVariableInfo(DmdType genericParameterType, DmdType genericArgumentType) {
GenericParameterType = genericParameterType ?? throw new ArgumentNullException(nameof(genericParameterType));
GenericArgumentType = genericArgumentType ?? throw new ArgumentNullException(nameof(genericArgumentType));
}
}
}