From 6d899096e4d739f0238a8710233c38e56c59fe04 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Sat, 10 Jul 2021 10:01:32 +0200 Subject: [PATCH] Fix #19 --- MatFileHandler/IMatFile.cs | 8 ++++++++ MatFileHandler/MatFile.cs | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/MatFileHandler/IMatFile.cs b/MatFileHandler/IMatFile.cs index da30d72..f961286 100755 --- a/MatFileHandler/IMatFile.cs +++ b/MatFileHandler/IMatFile.cs @@ -20,5 +20,13 @@ namespace MatFileHandler /// /// Variable name. IVariable this[string variableName] { get; set; } + + /// + /// Gets the variable with the specified name. + /// + /// The name of the variable to get. + /// When this method returns, contains the variable with the specified name, if it is found; otherwise, null. + /// True if the file contains a variable with the specified name; otherwise, false. + public bool TryGetVariable(string name, out IVariable? variable); } } \ No newline at end of file diff --git a/MatFileHandler/MatFile.cs b/MatFileHandler/MatFile.cs index ec17aab..4b01602 100755 --- a/MatFileHandler/MatFile.cs +++ b/MatFileHandler/MatFile.cs @@ -34,5 +34,11 @@ namespace MatFileHandler get => _variables[variableName]; set => _variables[variableName] = value; } + + /// + public bool TryGetVariable(string name, out IVariable value) + { + return _variables.TryGetValue(name, out value); + } } } \ No newline at end of file