// 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.Diagnostics;
using System.IO;
namespace Microsoft.AspNetCore.Razor.Evolution
{
///
/// An item in .
///
[DebuggerDisplay("{CombinedPath}")]
public abstract class RazorProjectItem
{
///
/// Path specified in .
///
public abstract string BasePath { get; }
///
/// Path relative to .
///
public abstract string Path { get; }
///
/// The absolute path to the file, including the file name.
///
public abstract string PhysicalPath { get; }
///
/// 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 virtual string CombinedPath
{
get
{
if (BasePath == "/")
{
return Path;
}
else
{
return BasePath + Path;
}
}
}
///
/// The extension of the file.
///
public virtual 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 virtual string Filename
{
get
{
var index = Path.LastIndexOf('/');
return Path.Substring(index + 1);
}
}
///
/// Path relative to without the extension.
///
public virtual string PathWithoutExtension
{
get
{
var index = Path.LastIndexOf('.');
if (index == -1)
{
return Path;
}
else
{
return Path.Substring(0, index);
}
}
}
}
}