diff --git a/src/AST/TranslationUnit.cs b/src/AST/TranslationUnit.cs index b1f8896c..17e191ab 100644 --- a/src/AST/TranslationUnit.cs +++ b/src/AST/TranslationUnit.cs @@ -31,28 +31,39 @@ namespace CppSharp.AST /// Contains the path to the file. public string FilePath; + private string fileName; + private string fileNameWithoutExtension; + /// Contains the name of the file. public string FileName { - get { return Path.GetFileName(FilePath); } + get { return fileName ?? (fileName = Path.GetFileName(FilePath)); } } /// Contains the name of the module. public string FileNameWithoutExtension { - get { return Path.GetFileNameWithoutExtension(FileName); } + get + { + return fileNameWithoutExtension ?? + (fileNameWithoutExtension = Path.GetFileNameWithoutExtension(FileName)); + } } /// Contains the include path. public string IncludePath; + private string fileRelativeDirectory; + private string fileRelativePath; + public string FileRelativeDirectory { get { + if (fileRelativeDirectory != null) return fileRelativeDirectory; var path = IncludePath.Replace('\\', '/'); var index = path.LastIndexOf('/'); - return path.Substring(0, index); + return fileRelativeDirectory = path.Substring(0, index); } } @@ -60,7 +71,8 @@ namespace CppSharp.AST { get { - return Path.Combine(FileRelativeDirectory, FileName); + return fileRelativePath ?? + (fileRelativePath = Path.Combine(FileRelativeDirectory, FileName)); } } }