-
Notifications
You must be signed in to change notification settings - Fork 809
Expand file tree
/
Copy pathHostsFileEntry.cs
More file actions
91 lines (77 loc) · 2.76 KB
/
HostsFileEntry.cs
File metadata and controls
91 lines (77 loc) · 2.76 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace NETworkManager.Models.HostsFileEditor;
/// <summary>
/// Class that represents a single entry in the hosts file.
/// </summary>
public class HostsFileEntry
{
/// <summary>
/// Indicates whether the entry is enabled or not.
/// </summary>
public bool IsEnabled { get; init; }
/// <summary>
/// IP address of the host.
/// </summary>
public string IPAddress { get; init; }
/// <summary>
/// Host name(s) of the host. Multiple host names are separated by a
/// space (equal to the hosts file format).
/// </summary>
public string Hostname { get; init; }
/// <summary>
/// Comment of the host.
/// </summary>
public string Comment { get; init; }
/// <summary>
/// Line of the entry in the hosts file.
/// </summary>
public string Line { get; init; }
/// <summary>
/// Creates a new instance of <see cref="HostsFileEntry" />.
/// </summary>
public HostsFileEntry()
{
}
/// <summary>
/// Creates a new instance of <see cref="HostsFileEntry" /> with parameters.
/// </summary>
/// <param name="isEnabled">Indicates whether the entry is enabled or not.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="hostname">Host name(s) of the host.</param>
/// <param name="comment">Comment of the host.</param>
public HostsFileEntry(bool isEnabled, string ipAddress, string hostname, string comment)
{
IsEnabled = isEnabled;
IPAddress = ipAddress;
Hostname = hostname;
Comment = comment;
var line = isEnabled ? "" : "# ";
line += $"{ipAddress} {hostname}";
if (!string.IsNullOrWhiteSpace(comment))
line += $" # {comment}";
Line = line;
}
/// <summary>
/// Creates a new instance of <see cref="HostsFileEntry" /> with parameters.
/// </summary>
/// <param name="isEnabled">Indicates whether the entry is enabled or not.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="hostname">Host name(s) of the host.</param>
/// <param name="comment">Comment of the host.</param>
/// <param name="line">Line of the entry in the hosts file.</param>
public HostsFileEntry(bool isEnabled, string ipAddress, string hostname, string comment, string line)
{
IsEnabled = isEnabled;
IPAddress = ipAddress;
Hostname = hostname;
Comment = comment;
Line = line;
}
/// <summary>
/// Overrides the ToString method to return the line of the entry in the hosts file.
/// </summary>
/// <returns>Line of the entry in the hosts file.</returns>
public override string ToString()
{
return Line;
}
}