/* 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.Generic; namespace dnSpy.Contracts.Decompiler { /// /// builder /// public sealed class MethodDebugScopeBuilder { /// /// Gets the span of this scope /// public ILSpan Span { get; set; } /// /// Gets all child scopes /// public List Scopes { get { if (scopes is null) scopes = new List(); return scopes; } } List? scopes; /// /// Gets all new locals in the scope /// public List Locals { get { if (locals is null) locals = new List(); return locals; } } List? locals; /// /// Gets all new imports in the scope /// public List Imports { get { if (imports is null) imports = new List(); return imports; } } List? imports; /// /// Gets all new constants in the scope /// public List Constants { get { if (constants is null) constants = new List(); return constants; } } List? constants; /// /// Constructor /// public MethodDebugScopeBuilder() { } /// /// Creates a new instance /// /// public MethodDebugScope ToScope() => new MethodDebugScope( Span, scopes is null ? Array.Empty() : ToScopes(scopes), locals is null || locals.Count == 0 ? Array.Empty() : locals.ToArray(), imports is null || imports.Count == 0 ? Array.Empty() : imports.ToArray(), constants is null || constants.Count == 0 ? Array.Empty() : constants.ToArray()); static MethodDebugScope[] ToScopes(List scopes) { var res = new MethodDebugScope[scopes.Count]; for (int i = 0; i < res.Length; i++) res[i] = scopes[i].ToScope(); return res; } } }