// // CodeVariableElement.cs - represents a CodeElement that declares a variable // // Author: // Michael Becker // // Copyright (c) 2011-2020 Mike Becker's Software // // This program 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. // // This program 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 this program. If not, see . using System; namespace UniversalEditor.ObjectModels.SourceCode.CodeElements { /// /// Represents a that declares a variable. /// public class CodeVariableElement : CodeElement, INamedCodeElement, IAccessModifiableCodeElement { public class CodeVariableElementCollection : System.Collections.ObjectModel.Collection { public CodeVariableElement Add(string VariableName, CodeDataType VariableDataType) { return Add(VariableName, VariableDataType, null); } public CodeVariableElement Add(string VariableName, CodeDataType VariableDataType, CodeElementReference VariableValue) { CodeVariableElement cve = new CodeVariableElement(); cve.Name = VariableName; cve.DataType = VariableDataType; cve.Value = VariableValue; base.Add(cve); return cve; } } public CodeVariableElement() { } public CodeVariableElement(string name) : this(name, null) { } public CodeVariableElement(string name, string[] datatype) { Name = name; DataType = datatype; Value = null; } public CodeVariableElement(string name, string[] datatype, CodeElementReference value) { Name = name; DataType = datatype; Value = value; } public CodeVariableElement(string name, CodeDataType datatype, CodeElementReference value) { Name = name; DataType = datatype; Value = value; } /// /// Gets or sets the name of the variable to declare. /// /// The name of the variable to declare. public string Name { get; set; } = String.Empty; public string GetFullName(string separator = ".") { return CodeElement.GetFullName(this, separator); } /// /// Gets or sets the default value of the declared variable. /// /// The default value of the declared variable. public CodeElementReference Value { get; set; } = null; /// /// Gets or sets the data type of the variable. /// /// The data type of the variable. public CodeDataType DataType { get; set; } = CodeDataType.Empty; /// /// Gets or sets the access modifiers for the variable. /// /// The access modifiers for the variable. public CodeAccessModifiers AccessModifiers { get; set; } = CodeAccessModifiers.None; /// /// Gets or sets a value indicating whether the variable declared by this /// should be passed by reference. /// /// true if this variable should be passed by reference; otherwise, false. public bool PassByReference { get; set; } = false; } }