/* 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 dnlib.DotNet; namespace dnSpy.Contracts.Decompiler { /// /// A parameter present in decompiled code /// public sealed class SourceParameter : ISourceVariable { /// /// The parameter /// public Parameter Parameter { get; } IVariable? ISourceVariable.Variable => Parameter; bool ISourceVariable.IsLocal => false; bool ISourceVariable.IsParameter => true; bool ISourceVariable.IsDecompilerGenerated => (Flags & SourceVariableFlags.DecompilerGenerated) != 0; /// /// Gets the name of the parameter the decompiler used. It could be different from the real name if the decompiler renamed it. /// public string Name { get; } /// /// Gets the type of the parameter /// public TypeSig Type { get; } /// /// Gets the hoisted field or null if it's not a hoisted parameter /// public FieldDef? HoistedField { get; } /// /// Gets the flags /// public SourceVariableFlags Flags { get; } /// /// Constructor /// /// Parameter /// Name used by the decompiler /// Type of local /// Flags public SourceParameter(Parameter parameter, string name, TypeSig type, SourceVariableFlags flags) { Parameter = parameter ?? throw new ArgumentNullException(nameof(parameter)); Name = name ?? throw new ArgumentNullException(nameof(name)); Type = type ?? throw new ArgumentNullException(nameof(type)); Flags = flags; } /// /// Constructor /// /// Parameter /// Name used by the decompiler /// Hoisted field /// Flags public SourceParameter(Parameter parameter, string name, FieldDef hoistedField, SourceVariableFlags flags) { Parameter = parameter ?? throw new ArgumentNullException(nameof(parameter)); Name = name ?? throw new ArgumentNullException(nameof(name)); HoistedField = hoistedField ?? throw new ArgumentNullException(nameof(hoistedField)); Type = hoistedField.FieldType; Flags = flags; } } }