/
NotFoundFileInfo.cs
63 lines (54 loc) · 1.74 KB
/
NotFoundFileInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
namespace Microsoft.Extensions.FileProviders
{
/// <summary>
/// Represents a non-existing file.
/// </summary>
public class NotFoundFileInfo : IFileInfo
{
/// <summary>
/// Initializes an instance of <see cref="NotFoundFileInfo"/>.
/// </summary>
/// <param name="name">The name of the file that could not be found</param>
public NotFoundFileInfo(string name)
{
Name = name;
}
/// <summary>
/// Always false.
/// </summary>
public bool Exists => false;
/// <summary>
/// Always false.
/// </summary>
public bool IsDirectory => false;
/// <summary>
/// Returns <see cref="DateTimeOffset.MinValue"/>.
/// </summary>
public DateTimeOffset LastModified => DateTimeOffset.MinValue;
/// <summary>
/// Always equals -1.
/// </summary>
public long Length => -1;
/// <inheritdoc />
public string Name { get; }
/// <summary>
/// Always null.
/// </summary>
public string? PhysicalPath => null;
/// <summary>
/// Always throws. A stream cannot be created for non-existing file.
/// </summary>
/// <exception cref="FileNotFoundException">Always thrown.</exception>
/// <returns>Does not return</returns>
[DoesNotReturn]
public Stream CreateReadStream()
{
throw new FileNotFoundException(SR.Format(SR.FileNotExists, Name));
}
}
}