// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; using System.IO; namespace Microsoft.AspNetCore.Razor.Language { /// /// An item in . /// [DebuggerDisplay("{" + nameof(DebuggerToString) + "()}")] public abstract class RazorProjectItem { /// /// Path specified in . /// public abstract string BasePath { get; } /// /// File path relative to . This property uses the project path syntax, /// using / as a path separator and does not follow the operating system's file system /// conventions. /// public abstract string FilePath { get; } /// /// The absolute physical (file system) path to the file, including the file name. /// public abstract string PhysicalPath { get; } /// /// The relative physical (file system) path to the file, including the file name. Relative to the /// physical path of the . /// public virtual string RelativePhysicalPath => null; /// /// Gets the file contents as readonly . /// /// The . public abstract Stream Read(); /// /// Gets a value that determines if the file exists. /// public abstract bool Exists { get; } /// /// The root relative path of the item. /// public string CombinedPath { get { if (BasePath == "/") { return FilePath; } else { return BasePath + FilePath; } } } /// /// The extension of the file. /// public string Extension { get { var index = FileName.LastIndexOf('.'); if (index == -1) { return null; } else { return FileName.Substring(index); } } } /// /// The name of the file including the extension. /// public string FileName { get { var index = FilePath.LastIndexOf('/'); return FilePath.Substring(index + 1); } } /// /// File path relative to without the extension. /// public string FilePathWithoutExtension { get { var index = FilePath.LastIndexOf('.'); if (index == -1) { return FilePath; } else { return FilePath.Substring(0, index); } } } private string DebuggerToString() { return CombinedPath; } } }